轴上显示字符串的R图 [英] R plot with strings showing in the axis
本文介绍了轴上显示字符串的R图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在根据住所的房间号(4位数字)绘制居民人数.房间号应该是字符串.但是当我使用as.character(RmNum)时,轴仍然显示为数字.
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?
推荐答案
使用功能axis
,您可以指定轴的位置,刻度线(at
)的放置位置并选择labels
.参数las=2
表示垂直于轴的标签.
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()
这篇关于轴上显示字符串的R图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文