teunbrand / ggh4x

ggplot extension: options for tailored facets, multiple colourscales and miscellaneous
https://teunbrand.github.io/ggh4x/
Other
534 stars 32 forks source link

Adding color to the primary strip breaks the overlap #124

Closed SimonW22 closed 10 months ago

SimonW22 commented 10 months ago

This may be a known issue. Based on your example plot here https://teunbrand.github.io/ggh4x/articles/Facets.html#themed-strips

image

Is it possible to color the strips without breaking the overlap? For example, can you add color so that the outer rows in the example plot 4,f,r are joined rather than split?

teunbrand commented 10 months ago

Sure, just use strip_nested() instead of strip_themed(). Example:

library(ggh4x)
#> Loading required package: ggplot2

p <- ggplot(mpg, aes(displ, hwy, colour = as.factor(cyl))) + geom_point()

ridiculous_strips <- strip_nested(
  # Horizontal strips
  background_x = elem_list_rect(fill = c("limegreen", "dodgerblue")),
  text_x = elem_list_text(colour = c("dodgerblue", "limegreen"),
                          face = c("bold", "bold")),
  by_layer_x = TRUE,
  # Vertical strips
  background_y = elem_list_rect(
    fill = c("gold", "tomato", "deepskyblue")
  ),
  text_y = elem_list_text(angle = c(0, 90)),
  by_layer_y = FALSE
)

p + facet_grid2(class ~ drv + year, strip = ridiculous_strips)

Created on 2023-09-08 with reprex v2.0.2

SimonW22 commented 9 months ago

Thank you for the clarification. It worked as intended.