r - barplot() 中的标签

标签 r

我正在尝试将名称添加到条形图的列中...每组中有 2 个条形图共享相同的名称。

我正在使用这样的代码:

l<-c(.6286, .2212, .9961, .5831, .8703, .6990, .9952, .9948)

r<-c(.2721, .5663, .0, .3961, .0696, .1180, .0, .0)

tab<-rbind(l,r)

plot<-barplot(tab, beside=TRUE, axisnames=FALSE, main = 'Time Spent Left vs. Right', sub = 'Female 2c', xlab= 'Days After Entry', ylab = 'Proportion of Time Spent', col=c('blue', 'red'), ylim = c(0,1))
legend('topleft', .8,  c('Left' , 'Right'), pch=c(.8), col=c('blue', 'red'))
names.arg = jd2c$d.in.p

names.arg=c(3,4,5,6,6,7,10,11) #listed for informational purposes, same as jd2c$d.in.p

jd2c$d.in.p 也在上面列出。由于某种原因,names.arg 函数似乎没有达到我的预期。即使我把它放在 barplot() 函数的括号内..

我做错了什么?

谢谢!

最佳答案

使用您的数据并适当设置 names.argaxisnames=TRUE,我得到了合理的结果。我调整了其他一些东西(设置las=1以将轴标签水平旋转,在图例中使用fill而不是col,摆脱了pch=0.8)。

par(las=1)
bnames <- c(3,4,5,6,6,7,10,11) #listed for informational purposes, same as jd2c$
plot<-barplot(tab, beside=TRUE, axisnames=TRUE,
              main = 'Time Spent Left vs. Right',
              sub = 'Female 2c', xlab= 'Days After Entry',
              ylab = 'Proportion of Time Spent',
              col=c('blue', 'red'), ylim = c(0,1),
              names.arg=bnames)
legend('topleft', cex=1,  c('Left' , 'Right'), fill=c('blue', 'red'))

enter image description here

关于r - barplot() 中的标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11509809/

相关文章:

r - 使用 Rvest 进行网页抓取——如果未找到节点,则返回 NA?

r - 按名称汇总数据,跨多个变量

r - 如何循环遍历列并创建不同的图?

r - gephi 中是否可以分离双向边?

r - 如何在 PostgreSQL 的 tryCatch 中使用 dbGetQuery?

r - 如何将radarchart ("fmsb"包中的默认标签字体类型更改为斜体)?

r - dmvnorm 的奇怪行为

r - 在 Amazon 上使用 R 的 GPU 包

R 相当于 Stata 本地或全局宏

r - 在shinydashboard中默认隐藏侧边栏