Skip to content

Fix legend key sizes #6485

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

teunbrand
Copy link
Collaborator

@teunbrand teunbrand commented May 29, 2025

This PR aims to fix #6484

Briefly, in #6340 we override user input in colour bars and descendants. We should've edited it, not override it.
Reprex from issue

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

p <- ggplot(mpg) +
  geom_point(aes(x = factor(cyl), y = displ, color = hwy)) +
  scale_color_fermenter(palette = "RdYlBu", direction = 1) +
  theme(legend.key.width = unit(0.25, "lines"))

plots <- list(
  p + ggtitle("default"),
  p + ggtitle("0.5 lines") + theme(legend.key.height = unit(0.5, "lines")),
  p + ggtitle("2.5 lines") + theme(legend.key.height = unit(2.5, "lines")),
  p + ggtitle("null") + theme(legend.key.height = unit(1, "null"))
)

cowplot::plot_grid(plotlist = plots)

Created on 2025-05-29 with reprex v2.1.1

@teunbrand teunbrand added this to the ggplot2 4.0.0 milestone May 29, 2025
@Yunuuuu
Copy link
Contributor

Yunuuuu commented May 29, 2025

In this line, we used the provided spacing which suggests that the input spacing should be preserved and not modified.

relative_sum <- sum(relative) + num_null(spacing)

But this line

spacing <- sum(rep(spacing, length.out = length(units) - 1))
it seems the spacing is being changed. Is this intentional?

@teunbrand
Copy link
Collaborator Author

Yeah we need to repeat the spacing for in between every guide. So for 1 guide, we need no spacing, for 2 guides we need 1x spacing, for 3 guides 2x etc.

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.key.height / width don't work in dev version
2 participants