I am using cowplot to arrange two plots with a common legend below. The approach works, yet the legend has whitespace around I would like to get rid of.
Note: I am ware of the ggpubr::ggarange common.legend option I though want to stick to cowplot::plot_grid (which masks ggpubr::get_legend)
library(tidyverse)
library(ggpubr)
library(cowplot)
theme_set(theme_cowplot())
p1 <- iris %>%
ggplot(aes(x=Sepal.Width,y=Petal.Width,color=Species)) +
geom_point() + coord_fixed()
p2 <- iris %>%
ggplot(aes(x=Sepal.Width,y=Petal.Width,color=Species)) +
geom_point() + coord_fixed()
compound_plot <- plot_grid(p1 + theme(legend.position="none"),
p2 + theme(legend.position="none"),
ncol = 2,
labels = c("A","B"))
legend <- get_legend(p1 +
theme(legend.direction = "horizontal",
legend.justification="center" ,
legend.box.just = "bottom"))
plot_grid(compound_plot,
legend,
ncol = 1)
Thanks in advance!
You can set
rel_heights
insideplot_grid