From 1120b7f57dc8cf96bf85ccb7c10e7983457e3a78 Mon Sep 17 00:00:00 2001 From: Teun van den Brand Date: Wed, 4 Dec 2024 13:26:55 +0100 Subject: [PATCH 1/3] the `reverse` setting gets embedded into `panel_params` --- R/coord-cartesian-.R | 7 ++++--- R/coord-sf.R | 5 +++-- R/coord-transform.R | 5 +++-- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/R/coord-cartesian-.R b/R/coord-cartesian-.R index 23e237583c..02e74dd5cd 100644 --- a/R/coord-cartesian-.R +++ b/R/coord-cartesian-.R @@ -102,8 +102,8 @@ CoordCartesian <- ggproto("CoordCartesian", Coord, self$range(panel_params) }, - transform = function(self, data, panel_params) { - reverse <- self$reverse %||% "none" + transform = function(data, panel_params) { + reverse <- panel_params$reverse %||% "none" x <- panel_params$x[[switch(reverse, xy = , x = "reverse", "rescale")]] y <- panel_params$y[[switch(reverse, xy = , y = "reverse", "rescale")]] data <- transform_position(data, x, y) @@ -113,7 +113,8 @@ CoordCartesian <- ggproto("CoordCartesian", Coord, setup_panel_params = function(self, scale_x, scale_y, params = list()) { c( view_scales_from_scale(scale_x, self$limits$x, params$expand[c(4, 2)]), - view_scales_from_scale(scale_y, self$limits$y, params$expand[c(3, 1)]) + view_scales_from_scale(scale_y, self$limits$y, params$expand[c(3, 1)]), + reverse = self$reverse %||% "none" ) }, diff --git a/R/coord-sf.R b/R/coord-sf.R index 3f96ff6aaf..4b1d7bc17d 100644 --- a/R/coord-sf.R +++ b/R/coord-sf.R @@ -86,7 +86,7 @@ CoordSf <- ggproto("CoordSf", CoordCartesian, target_crs <- panel_params$crs # CoordSf doesn't use the viewscale rescaling, so we just flip ranges - reverse <- self$reverse %||% "none" + reverse <- panel_params$reverse %||% "none" x_range <- switch(reverse, xy = , x = rev, identity)(panel_params$x_range) y_range <- switch(reverse, xy = , y = rev, identity)(panel_params$y_range) @@ -268,7 +268,8 @@ CoordSf <- ggproto("CoordSf", CoordCartesian, y_range = y_range, crs = params$crs, default_crs = params$default_crs, - !!!viewscales + !!!viewscales, + reverse = self$reverse %||% "none" ) # Rescale graticule for panel grid diff --git a/R/coord-transform.R b/R/coord-transform.R index 18230a1742..cd5c20b728 100644 --- a/R/coord-transform.R +++ b/R/coord-transform.R @@ -134,7 +134,7 @@ CoordTrans <- ggproto("CoordTrans", Coord, transform = function(self, data, panel_params) { # trans_x() and trans_y() needs to keep Inf values because this can be called # in guide_transform.axis() - reverse <- self$reverse %||% "none" + reverse <- panel_params$reverse %||% "none" x_range <- switch(reverse, xy = , x = rev, identity)(panel_params$x.range) y_range <- switch(reverse, xy = , y = rev, identity)(panel_params$y.range) trans_x <- function(data) { @@ -159,7 +159,8 @@ CoordTrans <- ggproto("CoordTrans", Coord, setup_panel_params = function(self, scale_x, scale_y, params = list()) { c( view_scales_from_scale_with_coord_trans(scale_x, self$limits$x, self$trans$x, params$expand[c(4, 2)]), - view_scales_from_scale_with_coord_trans(scale_y, self$limits$y, self$trans$y, params$expand[c(3, 1)]) + view_scales_from_scale_with_coord_trans(scale_y, self$limits$y, self$trans$y, params$expand[c(3, 1)]), + reverse = self$reverse ) }, From f8ff7b88c8f7939e6f7dff4abf59ac949c15d638 Mon Sep 17 00:00:00 2001 From: Teun van den Brand Date: Wed, 4 Dec 2024 13:27:57 +0100 Subject: [PATCH 2/3] ignore `reverse` during guide transformation --- R/coord-.R | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/R/coord-.R b/R/coord-.R index 6b0470e39e..f0ecbb0499 100644 --- a/R/coord-.R +++ b/R/coord-.R @@ -159,11 +159,13 @@ Coord <- ggproto("Coord", empty <- vapply(guides, inherits, logical(1), "GuideNone") guide_params <- panel_params$guides$get_params(aesthetics) aesthetics <- aesthetics[!empty] + # Guides are not subject to reverse logic + temp_params <- modify_list(panel_params, list(reverse = "none")) guide_params[!empty] <- Map( function(guide, guide_param, scale) { guide_param <- guide$train(guide_param, scale) - guide_param <- guide$transform(guide_param, self, panel_params) + guide_param <- guide$transform(guide_param, self, temp_params) guide_param <- guide$get_layer_key(guide_param, layers) guide_param }, From 2d86f8d958cda4110c8dbdb06556e35b33267c9d Mon Sep 17 00:00:00 2001 From: Teun van den Brand Date: Wed, 4 Dec 2024 13:28:08 +0100 Subject: [PATCH 3/3] fix incorrect bounding box calculation --- R/coord-radial.R | 1 + 1 file changed, 1 insertion(+) diff --git a/R/coord-radial.R b/R/coord-radial.R index de3bac2d00..c54333eda3 100644 --- a/R/coord-radial.R +++ b/R/coord-radial.R @@ -491,6 +491,7 @@ polar_bbox <- function(arc, margin = c(0.05, 0.05, 0.05, 0.05), return(list(x = c(0, 1), y = c(0, 1))) } arc <- sort(arc) + inner_radius <- sort(inner_radius) # X and Y position of the sector arc ends xmax <- 0.5 * sin(arc) + 0.5