R - barplot |如何控制酒吧的空间和宽度 [英] R - barplot | How to control space and width of bars

查看:142
本文介绍了R - barplot |如何控制酒吧的空间和宽度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望酒吧互相靠近,但不邻近(旁边= FALSE),并且我还希望酒吧略显瘦。我玩过 space width ,但我没有得到我想要的结果。
我更喜欢使用barplot函数,而不是使用ggplots,但如果没有办法想到它,那就没问题。



这是预期的barplot编辑手动从获得):





这是获得的结果:


使用的代码:

  jpeg(03.Annotation.Distribution.DMRs.All.jpeg)
bp1 = barplot(ann [,1:2],ylim = c(0,1.1),col = ann [,3],旁边= FALSE,空格= 10,
names.arg = c(Genome,DMRs),las = 3,xlab =Group,ylab =Frequency
main =DMR注释分布)
legend(top,legend = rownames(ann)[7:1],fill = ann [7:1,3],bty =n ,horiz = FALSE)
dev.off()

谢谢!

解决方案

酒吧的宽度必须做智慧h您正在使用的设备的大小。您可以根据您的数据设置一个新的绘图窗口并添加到该窗口中,即使 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()


I want the bars to be close to each other, but not adjacent (beside=FALSE), and I want also the bars to be slightly thin. I have played around with space and width but I am not getting my desired results. I prefer to stay with barplot function instead of using ggplots, but if there is no way thought it, that is ok.

This is the expected barplot (edited manually from the obtained):

And this is the obtained:

Code Used:

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()

Thankyou!

解决方案

The width of the bars has to do with the size of the device you're using. You can hack the spacing by setting up a new plot window based on your data and add to it, ie, make the xlim larger than you need.

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()

这篇关于R - barplot |如何控制酒吧的空间和宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆