I have a set of 3 scatterplots with a common legend that I'm making in R, does anyone know how to make a legend as its own separate figure?
Here's what I have so far:
library(ggplot2)
library(gridGraphics)
plot_grid(lymph_plot, imm_plot, fibro_plot, labels = c("A", "B", "C"), ncol = 3, nro1 = 1)
edit: Thank you Melissa Key, I was able to figure it out. I got the legend from the last scatterplot and used it as the last final element of the plot grid. Here's the code:
legend <- cowplot::get_legend(fibro_plot)
fibro_plot <- fibro_plot + theme(legend.position = "none")
plot_grid(lymph_plot, imm_plot, fibro_plot, legend, labels = c("A", "B", "C"),
rel_widths = c(1, 1, 1, 1/3), ncol = 4, nrow = 1)