tags:

views:

215

answers:

1

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 - whcih is not what I intended.

alt text

I am sorry that I can not explain it better.

+2  A: 

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

Alex Brown
Many Thanks Alex Brown. This is a really good solution!
Andreas
just realised that facetting makes the percentage sum to 100 in each facet. This is not good :-|
Andreas
Setting margins=T, the new margin ("all" facet) looks good. But then there is all the other facets ....
Andreas
Ok - I can always do: geom_bar(aes(y=..count../111)) - where 111 is the total number of cases. but that is not a nice way to do it. especially since i can't get ggplot to accept substituting 111 with a variable name that holds that value.
Andreas