I want to group the bars in a stacked barplot according to the values in another factor-variable. However, I want to do this without using facets.
I want to group the stacked bars according the afk
variable. The normal stacked bar plot can be made with:
ggplot(nl.melt, aes(x=naam, y=perc, fill=stemmen)) +
geom_bar(stat="identity", width=.7) +
scale_x_discrete(expand=c(0,0)) +
scale_y_continuous(expand=c(0,0)) +
coord_flip() +
theme_bw()
which gives an alfabetically ordered barplot:
I tried to group them by using x=reorder(naam,afk)
in the aes
. But that didn't work. Also using group=afk
does not have the desired effect.
Any ideas how to do this?
dput
ed data, is it correct? It seems that some quotes are missing. – Carlos Cinelli