From 50a495e2aa227a22317a385057f3142b8c19b768 Mon Sep 17 00:00:00 2001 From: Teun van den Brand <49372158+teunbrand@users.noreply.github.com> Date: Wed, 27 Sep 2023 09:09:07 +0200 Subject: [PATCH 1/2] Move CRS responsibility to CoordSf --- R/coord-sf.R | 15 ++++++++++----- R/guide-axis.R | 5 ----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/R/coord-sf.R b/R/coord-sf.R index 81207f2ce1..69523698fb 100644 --- a/R/coord-sf.R +++ b/R/coord-sf.R @@ -255,19 +255,24 @@ CoordSf <- ggproto("CoordSf", CoordCartesian, graticule$y_start <- sf_rescale01_x(graticule$y_start, y_range) graticule$y_end <- sf_rescale01_x(graticule$y_end, y_range) - list( + list2( x_range = x_range, y_range = y_range, graticule = graticule, crs = params$crs, default_crs = params$default_crs, - viewscales = viewscales + !!viewscales ) }, - setup_panel_guides = function(self, panel_params, guides, params = list()) { - params <- Coord$setup_panel_guides(panel_params$viewscales, guides, params) - c(params, panel_params) + train_panel_guides = function(self, panel_params, layers, params = list()) { + # 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( + vec_assign(panel_params, "default_crs", panel_params["crs"]), + layers, params + )$guides + panel_params }, backtransform_range = function(self, panel_params) { diff --git a/R/guide-axis.R b/R/guide-axis.R index eac32b2b98..581370b49d 100644 --- a/R/guide-axis.R +++ b/R/guide-axis.R @@ -135,11 +135,6 @@ GuideAxis <- ggproto( return(params) } - if (inherits(coord, "CoordSf")) { - # Positions already given in target crs - panel_params$default_crs <- panel_params$crs - } - aesthetics <- names(key)[!grepl("^\\.", names(key))] if (!all(c("x", "y") %in% aesthetics)) { other_aesthetic <- setdiff(c("x", "y"), aesthetics) From 905534a286a2badd8f4ce7f3cf2de2a901fff4d4 Mon Sep 17 00:00:00 2001 From: Teun van den Brand <49372158+teunbrand@users.noreply.github.com> Date: Fri, 29 Sep 2023 11:07:10 +0200 Subject: [PATCH 2/2] Fix typo --- R/coord-sf.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/coord-sf.R b/R/coord-sf.R index 69523698fb..0fe34293de 100644 --- a/R/coord-sf.R +++ b/R/coord-sf.R @@ -261,7 +261,7 @@ CoordSf <- ggproto("CoordSf", CoordCartesian, graticule = graticule, crs = params$crs, default_crs = params$default_crs, - !!viewscales + !!!viewscales ) },