Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

guide_custom does not adhere to legend order #6195

Open
julianbarg opened this issue Nov 21, 2024 · 1 comment · May be fixed by #6199
Open

guide_custom does not adhere to legend order #6195

julianbarg opened this issue Nov 21, 2024 · 1 comment · May be fixed by #6199
Labels
bug an unexpected problem or unintended behavior guides 📏

Comments

@julianbarg
Copy link

Even though guide_custom accepts an order argument, it always appears as the last legend in the sidebar.

Here is a reproducible example. Notice that you can use the order argument to reorder the color and shape legend but not change the position of the custom legend:

library(tidyverse)

df <- tribble(
  ~x, ~y, ~color, ~shape, 
  1, 2, "grey", 1,
  2, 2, "red", 2
) %>%
  mutate(shape = as.factor(shape))
circle <- grid::circleGrob()
custom <- guide_custom(circle, title = "My circle", order = 1,
                       width = unit(2, "cm"), height = unit(2, "cm"))
color_legend <- guide_legend(order = 3)
shape_legend <- guide_legend(order = 2)

ggplot(df, aes(x, y, color = color, shape = shape)) +
  geom_point() + 
  guides(color = color_legend, 
         shape = shape_legend,
         custom = custom)

R version 4.4.2 (2024-10-31)
Platform: x86_64-pc-linux-gnu
Running under: Debian GNU/Linux trixie/sid
ggplot2_3.5.1

@teunbrand
Copy link
Collaborator

Hi there, thanks for the report! I can reproduce the problem and it seems like a bug to me

@teunbrand teunbrand added bug an unexpected problem or unintended behavior guides 📏 labels Nov 25, 2024
@teunbrand teunbrand linked a pull request Nov 25, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug an unexpected problem or unintended behavior guides 📏
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants