Skip to content

fix redistribute_null_units #6488

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 1 commit into
base: main
Choose a base branch
from

Conversation

Yunuuuu
Copy link
Contributor

@Yunuuuu Yunuuuu commented May 29, 2025

fix #6487

@Yunuuuu
Copy link
Contributor Author

Yunuuuu commented May 29, 2025

  library(ggplot2)
  library(patchwork)
  p1 <- ggplot(mtcars) +
    geom_point(aes(mpg, disp)) +
    ggtitle("Plot 1")

  p3 <- ggplot(mtcars) +
    geom_point(aes(hp, wt, colour = mpg)) +
    ggtitle("Plot 3")
  p <- patchwork::wrap_plots(
    p1, p3 + scale_color_continuous(guide = guide_colorbar(
      theme = theme(legend.key.height = unit(1, "null"))
    )),
    ncol = 1L,
    guides = "collect"
  )
  print(p)

image

@teunbrand
Copy link
Collaborator

teunbrand commented May 30, 2025

Thank you for the PR! I like that this PR doesn't complicate the logic, however, I don't think it preserves some behaviour I care about (but haven't bothered to embody in a test yet).

In this example, the spacing between the legend should be around the same height as the guide_legend() (because legend has 3 keys, each of 1null height and we're using 3null spacing).
The following example is rendered using this PR's strategy:

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

p <- ggplot(mpg, aes(displ, hwy)) +
  geom_point(aes(colour = cty, fill = hwy, shape = drv)) +
  guides(fill = "legend")

p + theme(legend.spacing.y = unit(3, "null"), legend.key.height = unit(1, "null"))

But it should look like this:

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

@teunbrand teunbrand linked an issue May 30, 2025 that may be closed by this pull request
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 null unit legend key size failed
2 participants