ggplot geom_bar - 条形太宽

时间:2010-04-25 16:46:42

标签: r ggplot2

我很抱歉没有提供信息的标题。

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

然后是情节

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

问题是两个最右边的条(“年轻”,“旧”)太厚 - “东西”占据了整个宽度 - 这不是我想要的。

alt text http://www.imagechicken.com/uploads/1272295176088679800.png

对不起,我无法更好地解释它。

1 个答案:

答案 0 :(得分:3)

使用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