简体   繁体   中英

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. I am wondering can I obtain this figure using pure R code?

You can add text with 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(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. 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) 

在此输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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