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 order #6199

Merged
merged 3 commits into from
Jan 27, 2025
Merged

Guide custom order #6199

merged 3 commits into from
Jan 27, 2025

Conversation

teunbrand
Copy link
Collaborator

This PR aims to fix #6195.

Briefly, it applies the order argument, which is encoded into the names of guides after the merge step.

devtools::load_all("~/packages/ggplot2")
#> ℹ Loading ggplot2

df <- tibble::tribble(
  ~x, ~y, ~color, ~shape, 
  1, 2, "grey", 1,
  2, 2, "red", 2
) |>
  dplyr::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)

Created on 2024-11-25 with reprex v2.1.1

Copy link
Member

@thomasp85 thomasp85 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@teunbrand teunbrand merged commit e327a5e into tidyverse:main Jan 27, 2025
13 checks passed
@teunbrand teunbrand deleted the guide_custom_order branch January 27, 2025 15:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

guide_custom does not adhere to legend order
2 participants