Skip to content

Conversation

teunbrand
Copy link
Collaborator

This PR aims to fix #6293.

Briefly, the flip coord transform swaps the 'x' and 'y' names which makes sense for layers, but not so much the panel grid as it already recieves the variables in flipped form. The solution is to flip again before going into coord transform.

The reprex from the issue, notice the ticks and grid lining up again:

devtools::load_all("~/packages/ggplot2/")
#> ℹ Loading ggplot2
x <- -1:10
y <- -1:10
dati <- as.data.frame(x,y)

ggplot(dati, aes(x = x, y = y)) +
  geom_point() +
  scale_x_continuous(breaks = seq(-15, 15, by = 3), 
                     limits = c(-15,15)) +
  coord_flip()+
  theme(panel.grid.major = element_line(color = "blue"),
        panel.grid.minor = element_line(color = "red"))

Created on 2025-02-05 with reprex v2.1.1

Copy link
Member

@thomasp85 thomasp85 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@teunbrand teunbrand merged commit f6ef0c1 into tidyverse:main Mar 25, 2025
12 of 13 checks passed
@teunbrand teunbrand deleted the coord_flip_grid branch March 25, 2025 12:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Coord_flip() has some issues when interacting with panel.grid.major and panel.grid.minor
2 participants