ggeasy icon indicating copy to clipboard operation
ggeasy copied to clipboard

Reverse Legend Order

Open thomas-neitmann opened this issue 5 years ago • 0 comments

When creating a horizontal grouped bar chart the order in the legend does not match the order of the bars in the plot.

library(ggplot2)
library(dplyr)

p <- mtcars %>%
  group_by(cyl, am) %>%
  summarise(n = n()) %>%
  ggplot(aes(cyl, n, fill = factor(am))) +
  geom_col(position = "dodge") +
  coord_flip()

image

Changing this involves some functions I almost never use (and thus always forget).

p + guides(fill = guide_legend(reverse = TRUE))

image

My proposal is to have something like easy_reverse_legend(). What do you think @jonocarroll?

thomas-neitmann avatar Apr 11 '20 13:04 thomas-neitmann