在R中的小节上命名x轴 [英] naming x axis on barplot in R
本文介绍了在R中的小节上命名x轴的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在R中绘制一个小节 我有2个向量
I am trying to draw a barplot in R I have 2 vectors
x <- c(1,2,3,4)
y <- c(200,400,4000,255)
A <- rbind(x,y) # to make it into a matrix
barplot(A, ylim= c(0,5000))
我想将每个图1,2,3,4的底部放在x轴上.
I want to put at the base of each plot 1,2,3,4 on the x axis.
我该怎么做
谢谢
推荐答案
barplot(A, ylim= c(0,5000),names.arg=1:4)
这就是您的操作方式.
我的建议是,您应该仔细检查每个功能的帮助手册/文档. R图形函数通常具有许多用于各种目的的参数.
My suggestion is that you should check the help manual/doc for each function carefully. R graphic functions usually have lots of arguments for various purposes.
函数"barplot"返回每个条居中的x轴值.我们可以使用这些值作为参考来在每个条形图的顶部或其他任何位置(但不太直接)添加图例.
Function "barplot" returns the x-axis value where each bar is centred. We can use these values as a reference to add legend on top of each bar, or any where else (but less straightforward).
要添加在顶部
x.axis <-barplot(A, ylim= c(0,5000),names.arg=1:4)
text(x.axis, y, adj = c(0.5, 0)) ## you have defined "y"
这篇关于在R中的小节上命名x轴的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文