1

When using ggplot like this

data_frame(diamonds)

ggplot(diamonds,aes(cut)) +
  geom_bar() 

I get a plot as expected, however when I do this:

ggplot(diamonds,aes(cut)) +
  geom_bar() +
  coord_flip()

I flip the plot but the new "y" values go from bottom to top, is it possible to flip the coordinate AND have the values going from top to botton? So "fair" would be the top most value, then "good", then "very good"... etc.

enter image description here

Ronak Shah
  • 377,200
  • 20
  • 156
  • 213
EGM8686
  • 1,492
  • 1
  • 11
  • 22

1 Answers1

0

We can use fct_rev from forcats

library(forcats)
library(ggplot2)
ggplot(diamonds, aes(fct_rev(cut))) +
       geom_bar() +
       coord_flip() + 
       xlab('cut')

enter image description here

akrun
  • 874,273
  • 37
  • 540
  • 662