I am very new to coding and trying to learn the ways of ggplot2. I am stuck on trying to arrange my stacked bar chart by highest to lowest for one of the variables that is being stacked, so there is a clearer pattern.
I have had to use long data to make the stacked bar chart, but as a result can’t arrange by just the variable I want as its not the only value in Measure
. Data frame below:
data <- data.frame(
Measure = c("DVA", "FVA", "DVA", "FVA", "DVA", "FVA"),
Industry = c("Manufacturing", "Manufacturing", "Services", "Services", "Agriculture", "Agriculture"),
Share = c(10, 90, 20, 80, 30, 70)
)
And my ggplot2 code (which does work, just not arranged very usefully):
ggplot(data, aes(x = Industry, y = Share, fill = Measure)) +
geom_bar(stat = "identity") +
coord_flip()
Is there a way I can create this stacked bar chart, whilst arrange by lowest DVA share to highest?
amy is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.