I have a single variable that I want to plot, lets say the temperature in a place. Instead of the 'index =1,2,3.." in the horizontal axis, I want the name of place that I have in another column (corresponding to temperature at that place) instead of the 1,2,3. Is there a way to do this ?
something like this :
place1 32
place2 33
place3 43
place4 37
Basically I want to be able to use a column as labels for a plot.
Assuming your data is:
temp <- data.frame(temperature = c(32,33,43,37),
place = paste("Place", 1:4))
That is:
temperature place
1 32 Place 1
2 33 Place 2
3 43 Place 3
4 37 Place 4
You can use:
# Create a scatterplot, with an hidden x axis
plot(temp$temperature, pch=20, ylim=c(0, 50),
xaxt="n", xlab="Place", ylab="Temperature")
# Plot the axis separately
axis(1, at=1:4, labels=temp$place)
Or, if you want a barplot
barplot(temp$temperature, names.arg=rownames(temp$place))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With