R plot with strings showing in the axis

倖福魔咒の 提交于 2019-12-08 03:10:18

问题


I am plotting number of residents against the dorm room numbers (4 digits). The room numbers are supposed to be strings. But when I used as.character(RmNum), the axis still shows as numeric.

meanResidents = c(3, 4, 3, 2, 4, 5)
rmNumber = c(2034, 3043, 4012, 2035, 2022, 3013)
plot(as.character(rmNumber), meanResidents, xlab = as.character(rmNumber))

I would want the dorm numbers showing vertically in the axis. Can someone help me with that?


回答1:


With the function axis you can specify the position of the axis, where to put the tick marks (at) and choose the labels. The parameter las=2 means labels perpendicular to the axis.

plot(meanResidents, axes=FALSE, xlab="dorms")
axis(2)
axis(1, at=seq_along(meanResidents),labels=as.character(rmNumber), las=2)
box()



来源:https://stackoverflow.com/questions/17347991/r-plot-with-strings-showing-in-the-axis

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!