簡體   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