1

Using the multiplot() from the graphics cookbook:

multiplot <- function(..., plotlist=NULL, file, cols=1, layout=NULL) {

  require(grid)

  # Make a list from the ... arguments and plotlist
  plots <- c(list(...), plotlist)

  numPlots = length(plots)

  # If layout is NULL, then use 'cols' to determine layout
  if (is.null(layout)) {
    # Make the panel
    # ncol: Number of columns of plots
    # nrow: Number of rows needed, calculated from # of cols
    layout <- matrix(seq(1, cols * ceiling(numPlots/cols)),
                     ncol = cols, nrow = ceiling(numPlots/cols))
  }

  if (numPlots==1) {
    print(plots[[1]])

  } else {
    # Set up the page
    grid.newpage()
    pushViewport(viewport(layout = grid.layout(nrow(layout), ncol(layout),
                                  widths=0)))

    # Make each plot, in the correct location
    for (i in 1:numPlots) {
      # Get the i,j matrix positions of the regions that contain this subplot
      matchidx <- as.data.frame(which(layout == i, arr.ind = TRUE))

      print(plots[[i]], vp = viewport(layout.pos.row = matchidx$row,
                                  layout.pos.col = matchidx$col))
    }
  }
}

I need to alter the function so that the plots are printed with less space in between them.

I am showing no code of my attempts, due to the fact that I've looked at each sub-function in multiplot() and have yet to find any arguments that look like they solve this problem, so I do not know where to start.

I already wrote the plots in ggplot2, so I'd rather not re-write them is another package language.

Andrew Taylor
  • 3,438
  • 1
  • 26
  • 47
  • 2
    Does this help you? http://stackoverflow.com/questions/18252827/increasing-area-around-plot-area-in-ggplot2 If all plots in your multiplot show less white around the plot then you might get around adjusting the multiplot-function – David Nov 19 '15 at 13:20
  • 1
    Or even better, this here: http://stackoverflow.com/questions/15556068/removing-all-the-space-between-two-ggplots-combined-with-grid-arrange – David Nov 19 '15 at 13:21
  • Perfect. I've been fiddling with all of the other aspects of the plots' themes and didn't even think that my solution would be there. Thank you – Andrew Taylor Nov 19 '15 at 13:25

0 Answers0