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

This comment has been minimized.

Copy link

commented Feb 9, 2017

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

@bck243

This comment has been minimized.

Copy link

commented May 18, 2017

So helpful!!

@yfarjoun

This comment has been minimized.

Copy link

commented Apr 8, 2018

@zammyfh

This comment has been minimized.

Copy link

commented Aug 23, 2018

Amazing, thank you!

@mgei

This comment has been minimized.

Copy link

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

commented Oct 10, 2018

Thank you!

@jgarces02

This comment has been minimized.

Copy link

commented Dec 13, 2018

Thanks a lot!

@ptompalski

This comment has been minimized.

Copy link

commented Apr 10, 2019

@mgei 's method is slightly better as it works with a faceted graph and scales="free".

@novellisa

This comment has been minimized.

Copy link

commented Jul 4, 2019

Thank you!

@Dohanaga92

This comment has been minimized.

Copy link

commented Jul 17, 2019

perfecttt!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.