thomasp85 / patchwork

The Composer of ggplots
https://patchwork.data-imaginist.com
Other
2.46k stars 162 forks source link

`plot_layout(axes = "collect_y")` does not collect y axes correctly #354

Closed psychelzh closed 7 months ago

psychelzh commented 7 months ago

A simple example. The y axes for these two plots are indeed the same but collecting is not done. Tried corresponding "collect_x", which works as expect.

library(ggplot2)
library(patchwork)
d <- data.frame(x = rnorm(5), y = factor(LETTERS[1:5]))
p1 <- d |> ggplot(aes(x, y)) + geom_point()
p2 <- d |> ggplot(aes(x, y)) + geom_point()
p1 | p2 + plot_layout(axes = "collect_y")

p1 | p2 + plot_layout(axes = "collect")

Created on 2024-03-05 with reprex v2.1.0

thomasp85 commented 7 months ago

You are running into operator precedence issues, which are super annoying but not something patchwork can control as it works at the language level

(p1 | p2) + plot_layout(axes = "collect_y")

gives you the correct plot

psychelzh commented 7 months ago

Ah, I am sorry for such disturbance. I did not realize this.

psychelzh commented 7 months ago

Given this is not really related to patchwork, I am closing this. Thank you very much for explanation.