繁体   English   中英

R中的条形图标签:在绘图区域下方添加水平线

[英]barplot labels in R: add horizontal lines below the plot region

我的代码:

x <- c(10, 50, 20, 40)
barplot(x, names.arg=LETTERS[1:4])

我想要的是:

在此输入图像描述

我在R和Adobe Acrobat的帮助下制作了这个数字。 我想知道我可以使用纯R代码获得这个数字吗?

您可以使用mtext添加文本

mtext("E", side = 1, line = 3, adj = 0.375)
mtext("F", side = 1, line = 3, adj = 0.875)

然后用lines画线,但表示xpd=T

lines(c(0,3.5),c(-10,-10),xpd=TRUE)
lines(c(3.8,4.8),c(-10,-10),xpd=TRUE)

但是,您需要手动调整它。 在此输入图像描述

感谢Pascal。 我得到了另一个答案。

x <- c(10, 50, 20, 40)
barplot(x, names.arg=LETTERS[1:4])

mtext("E", side = 1, line = 3, adj = 0.375)
mtext("F", side = 1, line = 3, adj = 0.875)

axis(1, at=c(0.5,1,2,3,3.3), line=2.5, tick=T, labels=rep("",5), lwd=2, lwd.ticks=0)
axis(1, at=4+c(0.1,0.2,0.3,0.4,0.5),line=2.5,tick=T,labels=rep("",5), lwd=2, lwd.ticks=0) 

在此输入图像描述

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM