Skip to content

Commit f6ef0c1

Browse files
authored
Coord flip grid (#6319)
* swap x/y when using `coord_flip()` * include grid in snapshot * add news bullet
1 parent 56c20f6 commit f6ef0c1

File tree

4 files changed

+24
-2
lines changed

4 files changed

+24
-2
lines changed

NEWS.md

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# ggplot2 (development version)
22

3+
* Fixed regression with incorrectly drawn gridlines when using `coord_flip()`
4+
(@teunbrand, #6293).
35
* Deprecated functions and arguments prior to ggplot2 3.0.0 throw errors instead
46
of warnings.
57
* Functions and arguments that were soft-deprecated up to ggplot2 3.4.0 now

R/guides-grid.R

+5-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ guide_grid <- function(theme, panel_params, coord, square = TRUE) {
1212
y_minor <- setdiff(panel_params$y$mapped_breaks_minor(), y_major)
1313

1414
transform <- if (isTRUE(square)) {
15-
function(x) coord$transform(x, panel_params)
15+
if (inherits(coord, "CoordFlip")) {
16+
function(x) coord$transform(flip_axis_labels(x), panel_params)
17+
} else {
18+
function(x) coord$transform(x, panel_params)
19+
}
1620
} else {
1721
function(x) coord_munch(coord, x, panel_params)
1822
}

tests/testthat/_snaps/coord-flip/turning-off-secondary-title-with-coord-flip.svg

+11
Loading

tests/testthat/test-coord-flip.R

+6-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@ test_that("secondary labels are correctly turned off", {
44
ggplot(mtcars, aes(x = mpg, y = cyl)) +
55
geom_point() +
66
scale_x_continuous(sec.axis = dup_axis(guide = guide_axis(title = NULL))) +
7-
coord_flip()
7+
coord_flip() +
8+
theme_test() +
9+
theme(
10+
panel.grid.major.y = element_line(colour = "grey80"),
11+
panel.grid.major.x = element_line(colour = "grey90")
12+
)
813
)
914
})
1015

0 commit comments

Comments
 (0)