From 33a9a0247184f8495f0e1fd2329934192a04d342 Mon Sep 17 00:00:00 2001 From: Teun van den Brand Date: Wed, 5 Feb 2025 09:09:36 +0100 Subject: [PATCH 1/3] swap x/y when using `coord_flip()` --- R/guides-grid.R | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/R/guides-grid.R b/R/guides-grid.R index 6b8f116a24..1b2f1a4a99 100644 --- a/R/guides-grid.R +++ b/R/guides-grid.R @@ -12,7 +12,11 @@ guide_grid <- function(theme, panel_params, coord, square = TRUE) { y_minor <- setdiff(panel_params$y$mapped_breaks_minor(), y_major) transform <- if (isTRUE(square)) { - function(x) coord$transform(x, panel_params) + if (inherits(coord, "CoordFlip")) { + function(x) coord$transform(flip_axis_labels(x), panel_params) + } else { + function(x) coord$transform(x, panel_params) + } } else { function(x) coord_munch(coord, x, panel_params) } From f48baf3347b324e9671be1e085f2493f0fc51bfc Mon Sep 17 00:00:00 2001 From: Teun van den Brand Date: Wed, 5 Feb 2025 09:16:14 +0100 Subject: [PATCH 2/3] include grid in snapshot --- .../turning-off-secondary-title-with-coord-flip.svg | 11 +++++++++++ tests/testthat/test-coord-flip.R | 7 ++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/tests/testthat/_snaps/coord-flip/turning-off-secondary-title-with-coord-flip.svg b/tests/testthat/_snaps/coord-flip/turning-off-secondary-title-with-coord-flip.svg index ffb66ff639..207bd13c34 100644 --- a/tests/testthat/_snaps/coord-flip/turning-off-secondary-title-with-coord-flip.svg +++ b/tests/testthat/_snaps/coord-flip/turning-off-secondary-title-with-coord-flip.svg @@ -27,6 +27,17 @@ + + + + + + + + + + + diff --git a/tests/testthat/test-coord-flip.R b/tests/testthat/test-coord-flip.R index 0a346ebb24..fc63748418 100644 --- a/tests/testthat/test-coord-flip.R +++ b/tests/testthat/test-coord-flip.R @@ -4,7 +4,12 @@ test_that("secondary labels are correctly turned off", { ggplot(mtcars, aes(x = mpg, y = cyl)) + geom_point() + scale_x_continuous(sec.axis = dup_axis(guide = guide_axis(title = NULL))) + - coord_flip() + coord_flip() + + theme_test() + + theme( + panel.grid.major.y = element_line(colour = "grey80"), + panel.grid.major.x = element_line(colour = "grey90") + ) ) }) From ca430003be9a557673586f050eba25bae57a3bc9 Mon Sep 17 00:00:00 2001 From: Teun van den Brand Date: Wed, 5 Feb 2025 09:17:18 +0100 Subject: [PATCH 3/3] add news bullet --- NEWS.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/NEWS.md b/NEWS.md index 74b049ace5..16a835452e 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,7 @@ # ggplot2 (development version) +* Fixed regression with incorrectly drawn gridlines when using `coord_flip()` + (@teunbrand, #6293). * New parameters for `geom_label()` (@teunbrand and @steveharoz, #5365): * The `linewidth` aesthetic is now applied and replaces the `label.size` argument.