Closed trevorld closed 2 years ago
ggplot2::guide_colourbar()
not working with 3rd party geoms unless they explicitly call guide_colourbar()
with an expanded available_aes
argument: https://github.com/tidyverse/ggplot2/issues/4105I 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
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.
ggplot2::guide_colourbar()
(and itsguide_colorbar()
alias) only supportsfill
andcolour
aesthetics but it would be more useful to have a version that that also supportspattern_colour
,pattern_fill
, andpattern_fill2
aesthetics as well (which can be supported by explicitly adjusting itsavailable_aes
argument).guide_colourbar()
with an expanded defaultavailable_aes
.guide_colourbar()
. Only difference in behavior in function would be that the guide will no longer throw errors when used with thepattern_colour
,pattern_fill
, orpattern_fill2
aesthetics which doesn't seem to be a huge problem to me.color
aliases in both function name and aesthetic names...