我有一个要绘制的变量,比如说某个地方的温度。而不是水平轴中的'index = 1,2,3 ..”,我想要我在另一列中的地方名称(对应于那个地方的温度)而不是1,2,3。有吗一种方法来做到这一点?
像这样的东西:
place1 32
place2 33
place3 43
place4 37
基本上我希望能够使用一列作为绘图的标签。
假设您的数据是:
temp <- data.frame(temperature = c(32,33,43,37),
place = paste("Place", 1:4))
那是:
temperature place
1 32 Place 1
2 33 Place 2
3 43 Place 3
4 37 Place 4
您可以使用:
# 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)
或者,如果你想要一个条形图
barplot(temp$temperature, names.arg=rownames(temp$place))