2

Say I have three SQUARE plots p1 p2 p3 made from the ggplot2 package. I applied ggarrange command under ggpubr package to make a 1*3 plot after that. Here are the commands:

library(ggplot2)
library(ggpubr)
library(gridExtra)
data <- data.frame(matrix(seq(1, 30, 1), 2))

for(i in 1:5){
  plot1 <- ggplot(data = data, aes(y = data[, (i*3-2)])) + 
      theme(aspect.ratio = 1)
  plot2 <- ggplot(data = data, aes(y = data[, (i*3-1)])) + 
      theme(aspect.ratio = 1)
  plot3 <- ggplot(data = data, aes(y = data[, (i*3)])) + 
      theme(aspect.ratio = 1)
  p <- ggarrange(plot1, plot2, plot3,
                 ncol = 3, common.legend = TRUE, legend = "bottom")
  grid.arrange(p, top = paste(colnames(data)[i]), heights = c(1, 1))
}

The rmarkdown output (below) shows a large white space below the arranged plots:

enter image description here

Is there any way to remove it? What I thought is to change the default size of canvas..

Z.Lin
  • 28,055
  • 6
  • 54
  • 94
Jay
  • 21
  • 3
  • 3
    It's very hard to say without a [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example): we can't see your data, your individual plots, or your final plot that you're trying to debug. – camille Jan 17 '19 at 22:47
  • I have updated my question, hopefully it is more clear. The data itself is not important here. – Jay Jan 18 '19 at 14:46
  • The code from your example doesn't generate plots with a fixed amount of white space in R / Rstudio. You may want to check (& change) your default figure size in your rmarkdown document instead? – Z.Lin Jan 21 '19 at 02:26
  • Thanks Z.Lin, to change the default figure size in rmarkdown it squeezes each plot. I finally gave up using the command "ggarrange" and used grid.arrange to make the change. – Jay Jan 22 '19 at 15:57
  • 2
    I'd love to see your code for this, I'm currently using ggarrange and can't get rid of the white space between each plot – cgxytf Jan 29 '20 at 00:11

0 Answers0