简体   繁体   English

ggplot geom_bar-条太宽

[英]ggplot geom_bar - bars too wide

I am sorry for the non-informative title. 不好意思,我很抱歉。

> y=read.csv(textConnection(scan("",sep="\n",what="raw")))
"","org","art","type","length"
"191","gk","Finish","short",4
"147","ik","Attending","short",7
"175","gl","Finish","long",11
"192","il","Attending","long",95
"144","gm","Finish","between",5
"161","im","Attending","between",15
"164","tu","Something","young",8
"190","tv","Something","old",4

> decompress=function(x)x[rep(1:nrow(x),x$length),-ncol(x)]
> exstatus=decompress(y)

and then the plot 然后是情节

ggplot(exstatus, aes(x=type, fill=art))+
geom_bar(aes(y=..count../sum(..count..)),position="dodge")

The problem is that the two rightmost bars ("young", "old") are too thick - "something" takes up the whole width - which is not what I intended. 问题在于最右边的两个条(“年轻”,“旧”)太粗-“某物”占据了整个宽度-这不是我想要的。

alt text http://www.imagechicken.com/uploads/1272295176088679800.png 替代文字http://www.imagechicken.com/uploads/1272295176088679800.png

I am sorry that I can not explain it better. 对不起,我无法更好地解释它。

Use facet_grid instead of position="dodge" 使用facet_grid代替position =“ dodge”

  ggplot(exstatus, aes(x=art, fill=art))+
  geom_bar(aes(y=..count../sum(..count..))) + 
  facet_grid(~type,scales="free",space="free")

alt text http://www.imagechicken.com/uploads/1272294360054813000.png 替代文字http://www.imagechicken.com/uploads/1272294360054813000.png

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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