Skip to content

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