diff --git a/R/coord-.R b/R/coord-.R index 6b0470e39e..5fb65a9c85 100644 --- a/R/coord-.R +++ b/R/coord-.R @@ -147,7 +147,7 @@ Coord <- ggproto("Coord", panel_params }, - train_panel_guides = function(self, panel_params, layers, params = list()) { + train_panel_guides = function(self, panel_params, layers, params = list(), data = NULL) { aesthetics <- c("x", "y", "x.sec", "y.sec") @@ -163,8 +163,8 @@ Coord <- ggproto("Coord", guide_params[!empty] <- Map( function(guide, guide_param, scale) { guide_param <- guide$train(guide_param, scale) + guide_param <- guide$get_layer_key(guide_param, layers, data) guide_param <- guide$transform(guide_param, self, panel_params) - guide_param <- guide$get_layer_key(guide_param, layers) guide_param }, guide = guides[!empty], diff --git a/R/coord-map.R b/R/coord-map.R index 3ba9260206..447179160e 100644 --- a/R/coord-map.R +++ b/R/coord-map.R @@ -249,7 +249,7 @@ CoordMap <- ggproto("CoordMap", Coord, panel_params }, - train_panel_guides = function(self, panel_params, layers, params = list()) { + train_panel_guides = function(self, panel_params, layers, params = list(), data = NULL) { panel_params }, diff --git a/R/coord-polar.R b/R/coord-polar.R index b8855f52b9..32e4253540 100644 --- a/R/coord-polar.R +++ b/R/coord-polar.R @@ -175,7 +175,7 @@ CoordPolar <- ggproto("CoordPolar", Coord, panel_params }, - train_panel_guides = function(self, panel_params, layers, default_mapping, params = list()) { + train_panel_guides = function(self, panel_params, ...) { panel_params }, diff --git a/R/coord-radial.R b/R/coord-radial.R index bc933ea1d7..3c97220531 100644 --- a/R/coord-radial.R +++ b/R/coord-radial.R @@ -237,7 +237,7 @@ CoordRadial <- ggproto("CoordRadial", Coord, panel_params }, - train_panel_guides = function(self, panel_params, layers, params = list()) { + train_panel_guides = function(self, panel_params, layers, params = list(), data = NULL) { aesthetics <- c("r", "theta", "r.sec", "theta.sec") aesthetics <- intersect(aesthetics, names(panel_params$guides$aesthetics)) diff --git a/R/coord-sf.R b/R/coord-sf.R index d603d57de7..409e4d7fbe 100644 --- a/R/coord-sf.R +++ b/R/coord-sf.R @@ -276,7 +276,7 @@ CoordSf <- ggproto("CoordSf", CoordCartesian, panel_params }, - train_panel_guides = function(self, panel_params, layers, params = list()) { + train_panel_guides = function(self, panel_params, layers, params = list(), data = NULL) { # The guide positions are already in the target CRS, so we mask the default # CRS to prevent a double transformation. panel_params$guides <- ggproto_parent(Coord, self)$train_panel_guides( diff --git a/R/layout.R b/R/layout.R index 92a28216d7..16b8bb5ebd 100644 --- a/R/layout.R +++ b/R/layout.R @@ -219,26 +219,24 @@ Layout <- ggproto("Layout", NULL, invisible() }, - setup_panel_guides = function(self, guides, layers) { - - # Like in `setup_panel_params`, we only need to setup guides for unique - # combinations of x/y scales. - index <- vec_unique_loc(self$layout$COORD) - order <- vec_match(self$layout$COORD, self$layout$COORD[index]) + setup_panel_guides = function(self, guides, layers, data = NULL) { self$panel_params <- lapply( - self$panel_params[index], + self$panel_params, self$coord$setup_panel_guides, guides, self$coord_params ) - self$panel_params <- lapply( - self$panel_params, - self$coord$train_panel_guides, - layers, - self$coord_params - )[order] + self$panel_params <- Map( + function(params, data) { + self$coord$train_panel_guides(params, layers, self$coord_params, data = data) + }, + params = self$panel_params, + data = lapply(levels(self$layout$PANEL), function(i) { + lapply(data, function(x) vec_slice(x, x$PANEL == i)) + }) + ) invisible() }, diff --git a/R/plot-build.R b/R/plot-build.R index f855dddd78..7dfeaa2e63 100644 --- a/R/plot-build.R +++ b/R/plot-build.R @@ -98,7 +98,7 @@ ggplot_build.ggplot <- function(plot) { data <- layout$map_position(data) # Hand off position guides to layout - layout$setup_panel_guides(plot$guides, plot$layers) + layout$setup_panel_guides(plot$guides, plot$layers, data = data) # Complete the plot's theme plot$theme <- plot_theme(plot)