I need to make an arrange of plots in which each row of plots shares a common legend. All plots share the same units for y and x-axis. Below I show how my arrange of plots looks like:
I extract the common legend for each row as a plot and then I add it as an additional column in my arrange.
As you can see, the column with the legends "consume" a lot of space in the arrange, what could I do to reduce their margins in favour of the other two columns?
I used plot_grid
because I saw in this link that you can create common x and y-axis titles using ggdraw
.
You can use the rel_widths
argument of plot_grid
. Here's a reproducible example:
library(ggplot2)
library(cowplot)
library(ggpubr)
theme_set(theme_cowplot())
df <- data.frame(x = 1:12, y = (1:12)^2)
df$grp = c('Some', 'Things', 'In a legend')
p <- ggplot(df, aes(x, y, color=grp)) + geom_point()
leg <- get_legend(p)
leg <- as_ggplot(leg)
p = p + theme(legend.position = "none")
plot_grid(
p, p, leg,
p, p, leg,
ncol = 3, rel_widths=c(2,2,1)
)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.