我只想画一个变量,比方说一个地方的温度。我想要的不是横轴上的'index =1,2,3..‘,而是在另一列(对应于该位置的温度)中的地名,而不是1,2,3。有没有办法做到这一点?
如下所示:
place1 32
place2 33
place3 43
place4 37
基本上,我希望能够将列用作绘图的标签。
发布于 2013-10-13 12:23:22
假设您的数据是:
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))
https://stackoverflow.com/questions/19343641
复制