teunbrand / ggh4x

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

Alternative to ordering in facetted_pos_scales() #25

Closed teunbrand closed 3 years ago

teunbrand commented 4 years ago

As per discussion here, it might be a good idea to provide an alternative for matching up facet order with the extra scales. This might improve programmatic construction of the scales.

Potential options:

teunbrand commented 3 years ago

This should now work with a list of formulas provided to the x or y arguments. Example below:

library(ggh4x)
#> Loading required package: ggplot2

# Fixed limits for every facet except when `cyl == 6`
ggplot(mtcars, aes(mpg, wt)) +
  geom_point() +
  facet_wrap(~ cyl, scales = "free_y") +
  facetted_pos_scales(
    y = list(cyl == 6 ~ scale_y_continuous(),
             TRUE ~ scale_y_continuous(limits = range(mtcars$wt)))
  )

Created on 2021-01-07 by the reprex package (v0.3.0)

Pinging @r2evans who suggested this originally on SO to show it's implemented now :)