Ordering the bars of a stacked bar graph in ggplot from least to greatest?

I'm not sure about the way your data were generated (i.e. , whether you use a combination of cast/melt from the reshape package, which is what I suspect given the default name of your variables), but here is a toy example where sorting is done outside the call to ggplot. There might be far better way to do that, browse on SO as suggested by @Andy.

V1 Df, aes(x=factor(v2, levels=LETTERS1:24idx, ordered=TRUE), fill=v1)) + geom_bar() + opts(axis.text. X=theme_text(angle=90)) + labs(x="fullname") To sort in the reverse direction, add decr=TRUE with the order command. Also, as suggested by @Andy, you might overcome the problem with x-labels overlap by adding + coord_flip() instead of the opts() option.

Something like reorder(f,rep(1,length(f)),sum) will create a factor with levels ordered by frequency ... – Ben Bolker Nov 11 at 23:13 Thanks @BenBolker. I didn't manage to get this working in this particular configuration. Incidentally, one of Andy's comments which pointed to a related thread, here on SO, disappeared during the migration (don't know why!).

– chl Nov 12 at 11:47 1 ggplot(my. Df, aes(x=reorder(v2,rep(1,length(v2)),sum),fill=v1)) + geom_bar() + opts(axis.text. X=theme_text(angle=90)) + labs(x="fullname") works for me (without doing any other reordering of the factor) – Ben Bolker Nov 12 at 13:01 @Ben (+1) Thanks.

That's really more elegant, indeed. – chl Nov 12 at 16:03.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions