MarrangeGrob gives error for nrow

I am trying to create a bunch of ggplot2 graphs using the for loop and then saving them on a multi-page pdf document and I am having problems with marrangeGrob. Here is a sample code:

 Plots <- list()
 Plots[[1]] <- qplot(mtcars$mpg, mtcars$wt)
 Plots[[2]] <- qplot(mtcars$cyl, mtcars$wt)
 Plots[[3]] <- qplot(mtcars$mpg, mtcars$qsec)
 Plots[[4]] <- qplot(mtcars$cyl, mtcars$drat)

 # install.packages("gridExtra", dependencies = TRUE)
 library(gridExtra)

 MyPlots <- do.call(marrangeGrob, c(Plots, nrow = 1, ncol = 2))
 ggsave("My plots on multiple pages.pdf", MyPlots)

I used a similar version of the line do.call(marrangeGrob...in the past, and forced them to work, but now I get this error when trying to execute this line: Error: nrow * ncol >= n is not TRUE. The fact that code like this worked makes me think that since then, something in one of these packages has been updated. Any suggestions to fix this?

+4
source share
1 answer

The syntax has changed a bit with a new argument grobs. You have to use

marrangeGrob(grobs=Plots, nrow = 1, ncol = 2)

, ,

do.call(marrangeGrob, list(grobs=Plots, nrow = 1, ncol = 2))
+6

Source: https://habr.com/ru/post/1613239/


All Articles