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

3

我的代码:

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

我想要的是:

enter image description here

我用R和Adobe Acrobat的帮助制作了这个图表。我想知道是否可以使用纯R代码获得此图表?


4
这个链接能帮到你吗? - user3710546
@Pascal 很有用。谢谢。 - Ven Yao
2个回答

2

您可以使用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)

然而,您需要手动进行调整。 enter image description here

1
在R或RStudio中,如果我放大或缩小生成的图形,它会出现问题。图形下方的水平线会消失。 - Ven Yao

1
感谢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) 

enter image description here


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接