2010-04-25 165 views
0

我很抱歉无信息标题。ggplot geom_bar - 酒吧太宽

> 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

我很抱歉,我不能更好地解释它。

+0

如果你的数据是否有“完成”无值或在“年轻”和“老”“参加”,做自己然后呢?你是否想要一个带有空的第三栏的3杆组? – 2010-04-25 16:50:09

+0

也许尝试绘制你想要的图形(或者只是改变ggplot输出)。真的不清楚你想要什么。 – 2010-04-25 17:12:22

+0

是的。基本上有3个可能的酒吧。对于3个第一簇,应该可见两个柱,对于最后两个簇应该隐藏两个柱。 现在我计算两次“年轻”和“老” - 因此thichk酒吧。 我会尝试用一个更新的问题来更好地解释我的自我。谢谢尼古拉斯。 – Andreas 2010-04-25 19:27:52

回答

3

使用facet_grid而不是位置=“道奇”

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

+0

非常感谢Alex Brown。这是一个非常好的解决方案! – Andreas 2010-04-28 18:40:07

+0

刚刚意识到,在每个方面百分比总和为100。这不好: - | – Andreas 2010-04-29 11:07:23

+0

设置边距= T,新边距(“全部”面)看起来不错。但接下来还有其他方面...... – Andreas 2010-04-29 11:40:50