3

I have 8 plots and one legend that I would like to arrange in a 3x3 grid, so that the axes all align.

It works perfectly fine when I am not including the legend to my grid, but as soon as I have added the legend, my plots get shifted and are no longer aligned.

plot_grid(SiO2TiO2, SiO2Al2O3, SiO2FeO, SiO2MgO, SiO2CaO, SiO2Na2O, SiO2K2O, SiO2P2O5, align=c("hv"),nrow = 3, ncol = 3)

Plots aligned in a 3x3 grid without legend:

plot_grid(SiO2TiO2, SiO2Al2O3, SiO2FeO, SiO2MgO, SiO2CaO, SiO2Na2O, SiO2K2O, SiO2P2O5, legend, align=c("hv"),nrow = 3, ncol = 3)

Warning messages:

1: In align_plots(plotlist = plots, align = align) : Graphs cannot be vertically aligned. Placing graphs unaligned.

2: In align_plots(plotlist = plots, align = align) : Graphs cannot be horizontally aligned. Placing graphs unaligned.

Plots not aligned in a 3x3 grid with legend:

Anyone know how to align the legend with the plots? Thanks in advance!

mt1022
  • 16,834
  • 5
  • 48
  • 71
Servus
  • 373
  • 3
  • 14

1 Answers1

0

Maybe you have to define the width of your plots in grid.arrange command.

Like in the following example:

plot_grid(SiO2TiO2, SiO2Al2O3, SiO2FeO, SiO2MgO, SiO2CaO, SiO2Na2O, SiO2K2O, SiO2P2O5, legend, align=c("hv"), nrow = 3, ncol = 3, widths=c(2.3, 2.3, 2.3))
valz
  • 36
  • 3
  • Hi! When I try your example, I get the following error and no plot: > Error in ggplot_to_gtable(x) : Argument needs to be of class "ggplot" or "gtable" – Servus Jun 24 '17 at 15:12
  • Hi valz! Sorry for not responding, I didn't get a notification of a new post. I bypassed my issue with plotting 9 diagrams instead of 8, and putting the legend below those 9 plots (i.e. I created one grid with 3x3 plots, then created another grid with two rows, 1 column, where my first plot was the 3x3 grid, and the secon plot is the legend) – Servus Jul 21 '17 at 11:13