ggplot geom_bar - 酒吧太宽 [英] ggplot geom_bar - bars too wide
问题描述
对于非信息性标题,我感到抱歉。
> y = read.csv(textConnection(scan(,sep =\\\
,what =raw)))
,org,art,type,length
191,gk,Finish,short,4
147,ik,参加,短,7
175 ,gl,Finish,long,11
192,il,Attending,long,95
144,gm ,之间,5
161,im,参加,之间,15
164,tu,Something,young,8
190,tv,Something,old,4
>解压缩=函数(x)x [rep(1:nrow(x),x $ length), - ncol(x)]
> exstatus =解压缩(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
对不起,我无法更好地解释它。
使用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)
替代文字http://www.imagechicken.com/uploads/1272294360054813000.png
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
I am sorry that I can not explain it better.
Use facet_grid instead of 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
这篇关于ggplot geom_bar - 酒吧太宽的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!