Reverse order of discrete y axis in ggplot2
Solution 1:
There is a new solution, scale_*_discrete(limits=rev)
, example:
tibble(x=1:26,y=letters) %>%
ggplot(aes(x,y)) +
geom_point() +
scale_y_discrete(limits=rev)
Solution 2:
as per https://gist.github.com/jennybc/6f3fa527b915b920fdd5:
add scale_y_discrete(limits = rev(levels(theFactor)))
to your ggplot command.
Solution 3:
For a discrete axis, using reorder() worked for me. In context of the above problem, it would look something like this:
ggplot(df, aes(x = distanceRemaining, y = reorder(position, desc(position))))
Hope this helps.