Skip to content

Prevent ggplot2 from reversing the order of categories in horizontal legends. #5368

Closed as not planned

Description

Hello,
I have noticed that ggplot2 reverses the order of categories when the legend is horizontal (e.g., when legend.position = "top", see repex below). This has been raised as a previous issue (#4715), but I find it quite bothersome in practice (as I frequently need to modify the order of categories in the legend using guide_legend()).

Moreover, I believe that the order of categories in the legend should follow a coherent pattern with the order of categories in the graph, just as it does for vertical legends. This would make more sense.

What do you think about this?
I feel that this should not cause too significant a disruption for ggplot2 users.

# repex : 

iris%>%
  group_by(Species)%>%
  count()%>%
  ggplot(aes(x = n, y = "y", fill = Species))+
  geom_col(position = position_stack())+
  theme(legend.position = "top") 
  

image

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

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions