Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

plot_layout(axis_titles = "collect") does not work with fixed aspect ratio (and other coordinates beside coord_cartesian) #403

Closed
JFViola opened this issue Oct 25, 2024 · 2 comments

Comments

@JFViola
Copy link

JFViola commented Oct 25, 2024

I fear that this is the same problem as in issue https://github.com/thomasp85/patchwork/issues/366

Collecting the axis titles of several plots does not work if coord_fixed, coord_sf or theme(aspect.ratio=1) is involved:

(ggplot2 version 3.5.1, patchwork version 1.3.0

#works
p1 <- ggplot(mtcars) + 
  geom_point(aes(mpg, disp)) + 
  coord_cartesian()+
  ggtitle('Plot 1')

p2 <- ggplot(mtcars*-1) + 
  geom_point(aes(mpg, disp)) + 
  coord_cartesian()+
  ggtitle('Plot 2')

p1 + p2 +
  plot_layout(axis_titles  = 'collect')
#does not work
p1 <- ggplot(mtcars) + 
  geom_point(aes(mpg, disp)) + 
  coord_fixed()+
#alternatively
#coord_sf()+
#theme(aspect.ratio=1)+
  ggtitle('Plot 1')

p2 <- ggplot(mtcars*-1) + 
  geom_point(aes(mpg, disp)) + 
  coord_fixed()+
#alternatively
#coord_sf()+
#theme(aspect.ratio=1)+
  ggtitle('Plot 2')

p1 + p2 +
  plot_layout(axis_titles  = 'collect')
@thomasp85
Copy link
Owner

Yes, there is no way to ensure that plots with fixed aspects are actually occupying the same vertical or horizontal space when resizing the plot so collecting the axes doesn't make sense in general. For sf plots it is due to the fact that they do not use the new guide setup for their axes. If/when that changes in ggplot2 it should work out of the box

@thomasp85 thomasp85 closed this as not planned Won't fix, can't repro, duplicate, stale Oct 26, 2024
@JFViola
Copy link
Author

JFViola commented Oct 27, 2024

Alright thank you. I think it was a misunderstanding on my end, I wanted to collect labels not titles.

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

No branches or pull requests

2 participants