-
Notifications
You must be signed in to change notification settings - Fork 163
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
Can't combine align_patches with layout #207
Comments
Yeah. These are not meant to be used together. |
Is there any way to ensure the same alignment across multiple patchworks? The use case I have is I have a bunch of survival curves that I want to show in groups. Each group has a descriptive subtitle. I'd like the width of the guides and the axes to be aligned across all of the plots regardless of group. |
Ah - now I see what you want... I don't think that is possible right now. I'll consider how to add that in the future |
Thanks |
I came here to add my support for requesting this feature. My use case is identical to @bwiernik's (except I'm plotting scatter plots rather than survival curves). Looks like #254 is requesting also. Adding another reprex to illustrate lack of alignment across patches: library(ggplot2)
library(patchwork)
plot_list <- lapply(
X = 1:12,
FUN = \(i) {
ggplot(pressure, aes(temperature, pressure)) +
geom_point()
}
)
plot_groups <- list(1:6, 7, 8:10, 11:12)
layout <- c(
area(1, 1, 1, 1),
area(1, 2, 1, 2),
area(1, 3, 1, 3),
area(2, 1, 2, 1),
area(2, 2, 2, 2),
area(2, 3, 2, 3)
)
patchworks <- lapply(
X = seq_along(plot_groups),
FUN = \(i) {
title <- paste("Plot Group", i)
plots <- plot_list[plot_groups[[i]]]
plots |>
wrap_plots(design = layout) +
plot_annotation(title = title)
}
)
invisible(lapply(patchworks, print)) |
Actually, functionality to perform alignment and composition separately already exists in library(ggplot2)
library(cowplot)
all_plots <- lapply(
X = 1:12,
FUN = \(i) {
ggplot(pressure, aes(temperature, pressure)) +
geom_point()
}
)
plot_groups <- list(1:6, 7, 8:10, 11:12)
all_aligned_plots <- cowplot::align_plots(
plotlist = all_plots,
align = "hv",
axis = "tblr",
greedy = TRUE
)
cowplots <- lapply(
X = seq_along(plot_groups),
FUN = \(i) {
aligned_plots <- all_aligned_plots[plot_groups[[i]]]
cowplot <-
cowplot::plot_grid(
plotlist = aligned_plots,
nrow = 2,
ncol = 3
)
title <-
cowplot::ggdraw() +
cowplot::draw_label(
label = paste("Plot Group", i),
x = 0,
hjust = 0
) +
theme(plot.margin = margin(0, 0, 0, 7))
cowplot::plot_grid(
plotlist = list(title, cowplot),
ncol = 1,
rel_heights = c(0.1, 1)
)
}
)
invisible(lapply(cowplots, print)) |
I'm really not interested in using cowplot, so would really appreciate if this could be added to patchwork! |
I am trying to ensure that several patchworks have the same dimensions for their plots. However, I get errors when I try to align the dimensions, then include the resulting plots in a patchwork:
The text was updated successfully, but these errors were encountered: