teunbrand / ggh4x

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

Variable panel.spacing in facet_nested #92

Closed ColinConwell closed 1 year ago

ColinConwell commented 1 year ago

Thank you @teunbrand for this phenomenal package.

I am wondering if it's possible to add variable panel.spacing for different levels of facet_nested.

For example, imagine I have a singly nested facet (facet_nested( ~ var1 + var2).

Ideally, we could specify one size of panel.spacing for var1 and another size for var2.

I realize that though simple in conception, this might be monstrously hard in execution.

Any hack for solving this would be much appreciated!

teunbrand commented 1 year ago

Thank you for the kind words! This is currently not explicitly implemented and I don't think it will mingle well at the internal levels with how nested strips are implemented. Currently, the strips only touch the strips. However, if you don't mind doing a little bit of manual work, you may provide a vector of units to the panel.spacing theme element:

library(ggh4x)
#> Loading required package: ggplot2

ggplot(mpg, aes(displ, hwy)) +
  geom_point() +
  facet_nested(~ year + drv) +
  theme(
    panel.spacing.x = unit(c(2,2,4,2,2), "mm")
  )

Created on 2023-02-14 with reprex v2.0.2

ColinConwell commented 1 year ago

This does the trick perfectly well! Thanks so much for the rapid response.