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)))
@davidroberson

This comment has been minimized.

Copy link

davidroberson commented Feb 9, 2017

thanks this was very helpful. I found this via a google search.

@bck243

This comment has been minimized.

Copy link

bck243 commented May 18, 2017

So helpful!!

@yfarjoun

This comment has been minimized.

Copy link

yfarjoun commented Apr 8, 2018

@zammyfh

This comment has been minimized.

Copy link

zammyfh commented Aug 23, 2018

Amazing, thank you!

@mgei

This comment has been minimized.

Copy link

mgei commented Sep 18, 2018

You can also just specify it in the aesthetics
aes(x = reorder(the_factor, desc(the_factor)), ...)

@saskiakess

This comment has been minimized.

Copy link

saskiakess commented Oct 10, 2018

Thank you!

@jgarces02

This comment has been minimized.

Copy link

jgarces02 commented Dec 13, 2018

Thanks a lot!

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