简体   繁体   English

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

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

My code: 我的代码:

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

What I want is: 我想要的是:

在此输入图像描述

I made this figure with the help of R and Adobe Acrobat. 我在R和Adobe Acrobat的帮助下制作了这个数字。 I am wondering can I obtain this figure using pure R code? 我想知道我可以使用纯R代码获得这个数字吗?

You can add text with mtext 您可以使用mtext添加文本

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

and then draw line with lines but indicating xpd=T 然后用lines画线,但表示xpd=T

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

However, you need manually adjust it. 但是,您需要手动调整它。 在此输入图像描述

Thanks to Pascal. 感谢Pascal。 I got another answer. 我得到了另一个答案。

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