Multiple plots in for loop ignoring par

Here is one way to do it with cowplot::plot_grid. The plot_duo function uses tidyeval approach in ggplot2 v3.0.0 # install.packages(“ggplot2”, dependencies = TRUE) library(rlang) library(dplyr) library(ggplot2) library(cowplot) plot_duo <- function(df, plot_var_x, plot_var_y) { if (is.character(plot_var_x)) { print(‘character column names supplied, use ensym()’) plot_var_x <- ensym(plot_var_x) } else { print(‘bare column names supplied, use enquo()’) plot_var_x … Read more

Add a common Legend for combined ggplots

You may also use ggarrange from ggpubr package and set “common.legend = TRUE”: library(ggpubr) dsamp <- diamonds[sample(nrow(diamonds), 1000), ] p1 <- qplot(carat, price, data = dsamp, colour = clarity) p2 <- qplot(cut, price, data = dsamp, colour = clarity) p3 <- qplot(color, price, data = dsamp, colour = clarity) p4 <- qplot(depth, price, data = … Read more

Left align two graph edges (ggplot)

Try this, gA <- ggplotGrob(A) gB <- ggplotGrob(B) maxWidth = grid::unit.pmax(gA$widths[2:5], gB$widths[2:5]) gA$widths[2:5] <- as.list(maxWidth) gB$widths[2:5] <- as.list(maxWidth) grid.arrange(gA, gB, ncol=1) Edit Here’s a more general solution (works with any number of plots) using a modified version of rbind.gtable included in gridExtra gA <- ggplotGrob(A) gB <- ggplotGrob(B) grid::grid.newpage() grid::grid.draw(rbind(gA, gB))