From bb681f8afea60225508d5782776acd52e0dd2d41 Mon Sep 17 00:00:00 2001 From: maxsutton <47802620+maxsutton@users.noreply.github.com> Date: Mon, 28 Nov 2022 23:48:21 +1100 Subject: [PATCH 1/4] Set names of aesthetics after intersecting --- R/coord-.r | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/R/coord-.r b/R/coord-.r index 8213b3122e..d08756da0a 100644 --- a/R/coord-.r +++ b/R/coord-.r @@ -158,9 +158,11 @@ Coord <- ggproto("Coord", train_panel_guides = function(self, panel_params, layers, default_mapping, params = list()) { aesthetics <- c("x", "y", "x.sec", "y.sec") - names(aesthetics) <- aesthetics + # If the panel_params doesn't contain the scale, there's no guide for the aesthetic aesthetics <- intersect(aesthetics, names(panel_params$guides)) + + names(aesthetics) <- aesthetics panel_params$guides <- lapply(aesthetics, function(aesthetic) { axis <- substr(aesthetic, 1, 1) From 99b26cefcf082a84bf6bf0e98526f8e39cb06b60 Mon Sep 17 00:00:00 2001 From: maxsutton <47802620+maxsutton@users.noreply.github.com> Date: Mon, 28 Nov 2022 23:56:58 +1100 Subject: [PATCH 2/4] Add test to ensure fix is maintained --- tests/testthat/test-coord-.r | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/testthat/test-coord-.r b/tests/testthat/test-coord-.r index 59d51f7de4..eccac03852 100644 --- a/tests/testthat/test-coord-.r +++ b/tests/testthat/test-coord-.r @@ -24,3 +24,19 @@ test_that("message when replacing non-default coordinate system", { ) }) + +test_that("guide names are not removed by `train_panel_guides()`", { + gg <- ggplot() + data <- ggplot_build(gg) + + # Excerpt from ggplot_gtable.ggplot_built + plot <- data$plot + layout <- data$layout + data <- data$data + + layout$setup_panel_guides(plot$guides, plot$layers, plot$mapping) + + # Line showing change in outcome + expect_equal(names(layout$panel_params[[1]]$guides), + c("x", "y", "x.sec", "y.sec")) +}) From b33de870a742ce46291cfdeed97cd2a5b98d9d61 Mon Sep 17 00:00:00 2001 From: maxsutton <47802620+maxsutton@users.noreply.github.com> Date: Tue, 6 Dec 2022 10:33:36 +1100 Subject: [PATCH 3/4] Update NEWS.md --- NEWS.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index 582d9f2794..19cbc5e775 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,7 @@ # ggplot2 (development version) - +* Fixed a regression in `Coord::train_panel_guides()` where names of guides were + dropped (@maxsutton, #5063) + # ggplot2 3.4.0 This is a minor release focusing on tightening up the internals and ironing out some inconsistencies in the API. The biggest change is the addition of the From b7323872924ad0e1e3a423b80d93079ab8e5f3c1 Mon Sep 17 00:00:00 2001 From: maxsutton <47802620+maxsutton@users.noreply.github.com> Date: Fri, 9 Dec 2022 14:38:16 +1100 Subject: [PATCH 4/4] Update NEWS.md Co-authored-by: Hiroaki Yutani --- NEWS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index e94988f935..0df4de6cbf 100644 --- a/NEWS.md +++ b/NEWS.md @@ -4,7 +4,7 @@ (@teunbrand based on @clauswilke's suggestion, #5053). * The `lwd` alias now correctly replaced by `linewidth` instead of `size` (@teunbrand based on @clauswilke's suggestion #5051). -* Fixed a regression in `Coord::train_panel_guides()` where names of guides were +* Fixed a regression in `Coord$train_panel_guides()` where names of guides were dropped (@maxsutton, #5063) # ggplot2 3.4.0