I am making a dodged bar chart using ggplot with discrete x scale, the x axis are now arranged in alphabetical order, but I need to rearrange it so that it is ordered by the value of the y-axis (i.e., the tallest bar will be positioned on the left).
I tried order or sort, but result in sort the x-axis, but not the bars respectively.
What have I done wrong?
The best way for me was using vector with categories in order I need as limits
parameter to scale_x_discrete
. I think it is pretty simple and straightforward solution.
ggplot(mtcars, aes(factor(cyl))) +
geom_bar() +
scale_x_discrete(limits=c(8,4,6))