I am creating a taxanomic bar chart using ggplot but I need to change the layout of the stacked segments. This is my code to create the plot:
ggplot(full_genus_new, aes(x=as.factor(Var2), y=value, fill=Var1)) +
geom_bar(stat="identity", position = "fill", aes(order = -value)) +
scale_x_discrete() +
ylab("Relative Microbial Activity") +
facet_grid(cols=vars(PEDIS), scales = "free_x", space = "free_x") +
theme_classic() +
scale_fill_manual(values = Cb64k) +
scale_y_continuous(labels=percent_format()) +
theme(legend.position = "bottom", legend.text = element_text(size=8)) +
guides(fill=guide_legend(title="Taxa")) +
xlab("Patient") +
theme(legend.key.size = unit(0.5,'cm'))
Which produces the following:
How do I make it so the "other" group is at the bottom of the stack rather than in the middle so that the image looks cleaner?
This is how the data frame looks that I am working with, it is a tall form structure with Var2 being the patients: