diff --git a/R/geom-.r b/R/geom-.r index defac7a55a..1a4b9c0cf4 100644 --- a/R/geom-.r +++ b/R/geom-.r @@ -202,8 +202,20 @@ Geom <- ggproto("Geom", }, # Should the geom rename size to linewidth? - rename_size = FALSE - + rename_size = FALSE, + # Parameters to pass to scale$map() for each aesthetic: + # This can be either a named list (names are aesthetics, values are lists of parameters) + # or a function that takes a list of geom parameters as input and returns the list. + # The scale_params can be used to tell the scale map function a mapping method. + # e.g. scale_params = list(fill = list(mapping_method = "raw")) + # See the map method for ScaleContinuous in R/scale-.r for further details. + # + # The scale_params will be used to tell the scale map function the expected colour + # format, in case the geom prefers native colours (because it uses nativeRaster objects) + # instead of the default character vector: + # e.g. scale_params = list(fill = list("color_fmt" = "character")) # "#00FF00" + # e.g. scale_params = list(fill = list("color_fmt" = "native")) # from nativeRaster + scale_params = list() ) diff --git a/R/layer.r b/R/layer.r index 89ccb58028..a23a6688fe 100644 --- a/R/layer.r +++ b/R/layer.r @@ -391,6 +391,14 @@ Layer <- ggproto("Layer", NULL, self$geom$setup_data(data, self$computed_geom_params) }, + get_scale_params = function(self) { + if (is.function(self$geom$scale_params)) { + self$geom$scale_params(params = self$computed_geom_params) + } else { + self$geom$scale_params + } + }, + compute_position = function(self, data, layout) { if (empty(data)) return(data_frame0()) diff --git a/R/plot-build.r b/R/plot-build.r index b6102eed6e..cdf9930aec 100644 --- a/R/plot-build.r +++ b/R/plot-build.r @@ -88,7 +88,8 @@ ggplot_build.ggplot <- function(plot) { npscales <- scales$non_position_scales() if (npscales$n() > 0) { lapply(data, scales_train_df, scales = npscales) - data <- lapply(data, scales_map_df, scales = npscales) + scale_params <- by_layer(function(l, d) l$get_scale_params(), layers, data, "getting scale_params") + data <- mapply(scales_map_df, df = data, scale_params = scale_params, MoreArgs = list(scales = npscales), SIMPLIFY = FALSE) } # Fill in defaults etc.