I am trying to keep geombar from rearranging the x-axis on my stacked barplot.
Data frame looks like this:
I want to follow that same order for the group column (Female: HIV negative, Male: HIV negative, Female: HIV untreated, Male: HIV untreated, Female: HIV on ART, Male: HIV on ART)
This is my rscript to generate the stacked barplot:
data_long<- gather(data_wide, Genus , abundance, Sextaecvirus:Phi29virus, factor_key = TRUE )
ggplot(data_long, aes(x= Group, y= abundance, fill= Genus)) + geom_bar(stat = "identity") + geom_col(position = "fill")+ scale_y_continuous(labels = scales::percent).
Here is an example of how the stacked barplot x-axis looks like following my code: