-
-
Save jennybc/6f3fa527b915b920fdd5 to your computer and use it in GitHub Desktop.
scale_x_discrete(limits = rev(levels(the_factor))) |
So helpful!!
Thanks! I've linked this in a stackoverflow post https://stackoverflow.com/questions/28391850/r-reverse-order-of-discrete-y-axis-in-ggplot2
Amazing, thank you!
You can also just specify it in the aesthetics
aes(x = reorder(the_factor, desc(the_factor)), ...)
Thank you!
Thanks a lot!
@mgei 's method is slightly better as it works with a faceted graph and scales="free".
Thank you!
perfecttt!!!
so simple, many thanks
unfortunately this does not work with rlang/purrr functional programming:
scale_x_discrete(limits = rev(levels(!!sym(the_factor))))
Error in !sym(the_factor) : invalid argument type
And, as an aside, it does not work if the variable is a character vector rather than a factor (though of course that's an easy fix).
@jzadra The constructs like !!
are specific to tidyeval functions, which does not include base functions like levels()
.
Thanks. It's too bad that the scale_*_reverse()
only works on numeric; it seems like it would be useful to have it perform this behavior on factor and character.
This works now: scale_x_discrete(limits = rev)
This works now:
scale_x_discrete(limits = rev)
Thanks for this!
This works now:
scale_x_discrete(limits = rev)
Yes, this works! Many thanks
this helped me too, thanks!
Still helpful in 2024!!! Thanks so much :-)
thanks this was very helpful. I found this via a google search.