Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Reverse the order of a categorical axis in ggplot2
scale_x_discrete(limits = rev(levels(the_factor)))
@jennybc
Copy link
Author

jennybc commented May 5, 2020

@jzadra The constructs like !! are specific to tidyeval functions, which does not include base functions like levels().

@jzadra
Copy link

jzadra commented May 5, 2020

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.

@casa-henrym
Copy link

This works now: scale_x_discrete(limits = rev)

@ckm2016
Copy link

ckm2016 commented Oct 16, 2020

This works now: scale_x_discrete(limits = rev)

Thanks for this!

@AOurednikSFA
Copy link

This works now: scale_x_discrete(limits = rev)

Yes, this works! Many thanks

@tnat1031
Copy link

this helped me too, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment