Skip to content

Don't prepopulate legend key sizes #6340

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

Merged
merged 4 commits into from
Mar 25, 2025
Merged

Conversation

teunbrand
Copy link
Collaborator

This PR aims to fix #6339.

Briefly, it no longer prepopulates legend.key.width and legend.key.height from the global theme and instead uses the default path of computing these, which includes the local theme.

devtools::load_all("~/packages/ggplot2/")
#> ℹ Loading ggplot2
big_keys <- theme(legend.key.size = unit(3, "cm"))

ggplot(mpg, aes(displ, hwy, colour = drv)) +
  geom_point() +
  guides(colour = guide_legend(theme = big_keys))

Created on 2025-02-19 with reprex v2.1.1

Comment on lines +296 to +299
theme$legend.key.width <- rel(5)
valid_position <- c("bottom", "top")
} else {
theme$legend.key.height <- theme$legend.key.height * 5
theme$legend.key.height <- rel(5)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Since we haven't prepopulated these, we now just use a <rel> object to inherit a taller bar from legend.key.size.

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 d1b519d into tidyverse:main Mar 25, 2025
12 of 13 checks passed
@teunbrand teunbrand deleted the local_key_size branch March 25, 2025 14:31
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.

Legend size adjustment within guides
2 participants