I have a question concerning plot alignment in Cowplot.
I would like to align plots (ggplot) in a panel consisting of 3 columns. The first column has 2 plots (vertical aligned), the second column 1 plot, and the third also two plots (vertical aligned).
Example:
# Packages
library(tidyverse)
library(cowplot)
# Create sample data
df <- data.frame(replicate(2,sample(0:10,10,rep=TRUE)))
# Create sample plots
plot.a1 <- ggplot(df, aes(x=df$X1, y=df$X2)) +
geom_point()
plot.a2 <- plot.a1
plot.a <- plot_grid(plot.a1, plot.a2, align = "v", ncol = 1, nrow = 2)
plot.b <- plot.a1
plot.c1 <- plot.a1
plot.c2 <- plot.a1
plot.c <- plot_grid(plot.c1, plot.c2, align = "v", ncol = 1, nrow = 2)
# Create panel figure
plot_grid(plot.a, plot.b, plot.c, labels = c("A", "B", "C"), align = "h", axis = "b", nrow = 1, ncol = 3)
I expected that by aligning the panel horizontally (align = "h", axis = "b")
the bottom axis of the plot would align correctly, however I am doing something wrong.
How can I align the columns horizontally (by the bottom axis)?
plot_grid
is making its own margins for the resulting plot panel.
If you need plot.b
to align with the others, just call:
plot.b <- plot_grid(plot.a1)
Even though it is empty. Then, the last plot_grid()
call is passed three element, all of which are the same.
plot_grid(plot.a, plot.b, plot.c, labels = c("A", "B", "C"), align = "h", axis = "b", nrow = 1, ncol = 3)