簡體   English   中英

R-barplot | 如何控制條的空間和寬度

[英]R - barplot | How to control space and width of bars

我希望這些條彼此靠近,但不相鄰(beside=FALSE) ,並且我也希望這些條稍細。 我已經在spacewidth玩了,但是沒有得到想要的結果。 我更喜歡使用barplot函數而不是使用ggplots,但是如果沒有辦法,那就可以了。

這是預期的條形圖(根據獲得的條形圖進行手動編輯):

所需的Barplot

這是獲得的:

在此處輸入圖片說明

使用的代碼:

jpeg("03.Annotation.Distribution.DMRs.All.jpeg")
bp1 = barplot(ann[,1:2], ylim=c(0,1.1), col=ann[,3], beside=FALSE, space=10, 
              names.arg=c("Genome","DMRs"), las=3, xlab="Group", ylab="Frequency", 
              main="Annotation distribution on DMRs")
legend("top",legend=rownames(ann)[7:1], fill=ann[7:1,3], bty="n", horiz=FALSE)
dev.off()

謝謝!

條形的寬度與您使用的設備的大小有關。 您可以通過根據數據設置一個新的繪圖窗口並添加到其中來增加間距,即使xlim大於所需的范圍。

jpeg('./tmp.jpg', width = 250, height = 480, bg = 'grey90')
plot.new()
plot.window(c(0,6), c(0,1))
with(mtcars,
     barplot(prop.table(table(gear, vs), 2), col = 1:3, add = TRUE,
             legend.text = unique(gear), xlab = 'vs'))
dev.off()

在此處輸入圖片說明

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM