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

Fix blank strip text with multilayered strips #4384

Merged
merged 3 commits into from
Mar 22, 2021

Conversation

teunbrand
Copy link
Collaborator

This PR aims to fix #4050, wherein an error occurs in facet_grid() when the strip text is a blank element and there are two variables determining the strips. This also caused an inelegant warning in facet_wrap() that should now also be remedied.
Instead of returning an n by m matrix of zeroGrobs, the assemble_strips() internal function now returns an n-length list of zeroGrobs regardless of m. This then satisfies the FacetWrap/Grid$draw_panel() methods' assumption that the length of the strip-grobs is equal to the number of panels (for facet_wrap()) or columns/rows (for facet_grid()).

The following should now work without warnings or errors:

library(ggplot2)

df <- data.frame(
  x = 1, y = 1, a = "A", b = c("B", "C")
)

p <- ggplot(df, aes(x, y)) +
  geom_point() +
  theme(strip.text = element_blank())

# Was warning before, now doesn't warn
p + facet_wrap(~ a + b)

# Was error before, now runs fine
p + facet_grid(~ a + b)

Copy link
Member

@yutannihilation yutannihilation left a comment

Choose a reason for hiding this comment

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

Looks good, thanks!

Could you add a news item? As at least two users faced this problem, I think this is worth a news.

@teunbrand
Copy link
Collaborator Author

Yes, sure thing. Thanks for approving!

@yutannihilation yutannihilation merged commit eca0862 into tidyverse:master Mar 22, 2021
@yutannihilation
Copy link
Member

Thanks!

@teunbrand teunbrand deleted the strip_blank branch March 22, 2021 14:54
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.

strip.text.y = element_blank() yields an error when there are multiple layers of strip labels
2 participants