R:在水平条形图上的条形图旁添加值
问题描述:
我试图从我的矢量中将值添加到我的水平条形图右侧,但未成功。我试图修复和混合一些代码,以及我的x和y标签及其展示位置。这里是我的代码R:在水平条形图上的条形图旁添加值
a <- c(315, 149, 128, 97, 68, 49, 38, 0)
par(las=1)
par(mgp=c(4.5,1,0))
par(mar=c(5,6,4,3)+0.05)
barplot(a, horiz = TRUE, col="darkolivegreen3",
main="Average Occupancy",
ylab = "Hours",
names.arg = c("0-1h", "1-2h", "2-3h", "3-4h", "4-5h", "5-6h", "6-7h", "7-8h"))
mtext(side=1, text="Minutes", line=2.5)
答
这是你的图的代码。
a <- c(315, 149, 128, 97, 68, 49, 38, 0)
par(mar=c(4,4,1,1), oma=c(0,0,0,0), las=1)
posbar <- barplot(a, horiz = TRUE, col="darkolivegreen3",
main="Average Occupancy",
ylab = "", xlab="", xlim=c(0,350),
names.arg = c("0-1h", "1-2h", "2-3h", "3-4h", "4-5h", "5-6h", "6-7h", "7-8h"))
mtext(side=1, text="Minutes", line=2.5)
mtext(side=2, text="Hours", line=3, las=0)
text(y=posbar, x=a, pos=4,labels=a)
不,我想从一个向量中的值是这些小节的权利。如果我不够清楚,我很抱歉。为了清晰起见,我编辑了我的文本 – arezaie
请检查我的答案的更新版本 –
就是这样!谢谢! – arezaie