trevorld / ggpattern

ggplot geoms with pattern fills
https://trevorldavis.com/R/ggpattern/dev/
Other
359 stars 18 forks source link

Export tweaked version of `ggplot2::guide_colourbar()`? #64

Closed trevorld closed 2 years ago

trevorld commented 2 years ago
trevorld commented 2 years ago
coolbutuseless commented 2 years ago

I struggled with this same issue with the ggsvg package - where any named aesthetic could be considered to be a colour (and new aesthetics are created on-the-fly)

My solution was not elegant: I rewrote every single colour/fill scale such that the aesthetics argument no longer had a default, and I would then pass this as the available_aes to guide_colorbar() i.e.

scale_svg_colour_gradient <- function(aesthetics,
                                      ...,
                                      low        = "#132B43",
                                      high       = "#56B1F7",
                                      space      = "Lab",
                                      na.value   = "grey50",
                                      guide      = ggplot2::guide_colorbar(available_aes = aesthetics)) {
  ggplot2::continuous_scale(
    aesthetics,
    scale_name = "gradient",
    palette    = scales::seq_gradient_pal(low, high, space),
    na.value   = na.value,
    guide      = guide,
    ...
  )
}

It may be possible to do with

trevorld commented 2 years ago

Thanks! The {ggpattern} scales should work now after explicitly specifying appropriate available_aes arguments to guide_colourbar() instead of just using "colourbar". Just wondering if we should export a helper guide function in case users wanted to explicitly set a guide since guide_colourbar() isn't intuitive for 3rd-party geoms. Probably not many people using a continuous colour scale AND setting a custom colourbar guide so I guess we can reasonably defer on such a feature for now.