Closed teunbrand closed 9 months ago
dedup_axes
name and think the functionality should work in the same way as the guide collecting functionality. This suggests adding a axes
and axis_titles
argument to plot_layout()
that can take "keep"
and "collect"
as valuesThanks for your thoughts Thomas!
This suggests adding a axes and axis_titles argument to plot_layout() that can take "keep" and "collect" as values
Is there a need to discriminate the x- or y-direction and if so, how would you like this to be exposed? We could add x_axes = NULL
and y_axes = NULL
arguments, where x_axes = x_axes %||% axes
or something. Or should the options be "keep"
, "collect"
, "collect_x"
and "collect_y"
?
If we should discriminate I think the last suggestion is the best since we already have committed to string values
Latest updates:
axis = 'collect{_x/_y}'
can be used and axis_titles
in similar fashion.I think this PR is now in a good place for review.
library(ggplot2)
devtools::load_all("~/packages/patchwork/")
#> ℹ Loading patchwork
theme_set(theme_grey())
p1 <- ggplot(mtcars) +
aes(x = cyl, y = disp) +
geom_point()
p2 <- p1 +
theme(axis.text = element_text(colour = "red")) +
labs(x = "foo", y = "bar")
p1 <- p1 + scale_y_continuous(labels = \(x) paste0("a long label indicating ", x))
p1 + p1 + p1 + p2 + plot_layout(2, 2, axes = "collect", axis_titles = "collect")
Created on 2023-11-02 with reprex v2.0.2
Thank you!
Amazing!
Hi,
It seems like this doesn't do anything when we use |
and /
instead of plot_layout
definition. Is this intended?
p1 <- ggplot(mtcars) +
aes(x = cyl, y = disp) +
geom_point()
p2 <- p1 +
theme(axis.text = element_text(colour = "red")) +
labs(x = "foo", y = "bar")
p1 <- p1 + scale_y_continuous(labels = \(x) paste0("a long label indicating ", x))
((p1 | p1) / (p1 | p2)) + plot_layout(axes = "collect", axis_titles = "collect")
Is this intended?
Yes and no. The merging mechanism don't work over multiple nesting levels, which is what you've induced with your layout code. We had accepted this limitation, so while we agree that it doesn't work out ideally in your case, it generally does what we had intended. The solution to the problem would be to use an unnested layout design.
Fair enough. Is there a way to raise a warning in this situation? Or alternatively mention it on the documentation? I could make a pull request (although the former seems to be complicated)
This PR aims to fix #150.
Briefly, it adds options to
plot_layout()
that allows the user to:What can and cannot be merged is mostly determined by a homebrew 2D run-length encoding of a simplified layout.
An example using identical plots to showcase the sharing. Notice the following:
Another example showing not-merge behaviour for the last plot. Notice the following:
Created on 2023-10-23 with reprex v2.0.2
Why is this PR still WIP?