Skip to content

Drop zeroGrob() guides #5645

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 2 commits into from
Jan 16, 2024
Merged

Conversation

teunbrand
Copy link
Collaborator

This PR to the RC aims to fix a bug uncovered during reverse dependency checks.

Briefly, in some unnatural circumstances you can create a guide that survives all steps but decides to draw a zeroGrob().
Guides$package_box() cannot estimate the gtable size of these guides.

library(ggplot2)

ggplot(mpg[1:2, ], aes(displ, cty, colour = c(1, 4))) +
  geom_point() +
  scale_colour_continuous(
    limits = c(2.4, 2.6), breaks = c(1, 4),
    guide = "legend"
  )
#> Error in upgradeUnit.default(x): Not a unit object

Created on 2024-01-15 with reprex v2.0.2

The solution in this PR is to drop empty guides at the Guides$draw() step. The reason we might not want to censor guides as soon as we detect the key is empty, is because some (extension) guides might have genuine reasons for not using a key.

@teunbrand teunbrand changed the base branch from main to rc/3.5.0 January 15, 2024 14:35
@teunbrand teunbrand added this to the ggplot2 3.5.0 milestone Jan 15, 2024
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 d5c2f1f into tidyverse:rc/3.5.0 Jan 16, 2024
@teunbrand teunbrand deleted the drop_empty_guides branch January 16, 2024 10:24
thomasp85 pushed a commit that referenced this pull request Feb 23, 2024
* drop empty guides

* add test
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.

2 participants