How to center a plot within a grid using ggarrange() from the ggpubr package?

Using ggarrange() from the “ggpubr” package, how can I create a grid where the last plot at the bottom is centered only in the bottom row?

Additionally, how can I share a single legend among the plots? In this setup, the plot 3 always has its independent legend if I change the legend = "none" to common.legend = TRUE.

# Packages
library(ggplot2)
library(ggpubr)

# Plots
plt.1 <- ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width, colour = Species)) + 
  geom_point(size = 0.2) +
  theme(
    axis.ticks = element_line(size = 0.2),
    axis.title = element_text(size = 7),axis.text = element_text(size = 7),
    panel.grid.major = element_blank(), panel.grid.minor = element_blank()
  )
plt.2 <- plt.1
plt.3 <- plt.1 

# Building a grid of plots
ggarrange(plt.1, plt.2, 
          ggarrange(plt.3, ncol = 1, legend = "none"), 
          nrow = 2,
          ncol = 2,
          legend = "none")

# Saving the image
ggsave("img.png", height = 6, width = 6, dpi = 300, bg = 'white')

enter image description here

I’ve been studying this topic for the past few hours, but I can only find examples where the top plot is centered and fills the entire first row. The script I sent is my latest unsuccessful attempt.

Below are the links I consulted:
https://www.datanovia.com/en/lessons/combine-multiple-ggplots-into-a-figure/
https://www.sthda.com/english/articles/24-ggpubr-publication-ready-plots/81-ggplot2-easy-way-to-mix-multiple-graphs-on-the-same-page/
Aligning multiple plot in egg::ggarrange

  • This is quite trivial to achieve using the patchwork package. Is there some reason you need to use ggarrange?

    – 

  • 1

    @Anderson, both cowplot() and ggarrange() offer straightforward means of doing this. See sthda.com/english/articles/24-ggpubr-publication-ready-plots/…. Cheer!

    – 

  • I did a large volume of work using ggpubr() imagining that this wouldn’t be an impediment. In case I can’t resolve it with that, I will be forced to readjust a lot of things. But I will take note of the suggestions given here.

    – 

Leave a Comment