marrangeGrob给出了nrow的错误

Lau*_*raS 4 r ggplot2 gridextra r-grid

我正在尝试使用for循环创建一堆ggplot2图,然后将它们保存在多页pdf文档中,而我遇到了marrangeGrob问题.这是一些示例代码:

 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)
Run Code Online (Sandbox Code Playgroud)

我过去使用过类似版本的do.call(marrangeGrob...线程并让它们工作,但现在,当我尝试执行该行时,我收到此错误:Error: nrow * ncol >= n is not TRUE.类似于以前的代码工作的事实使我认为其中一个包中的某些内容已经更新.对于如何解决这个问题,有任何的建议吗?

bap*_*ste 6

grobs参数的语法有所改变.你应该用

marrangeGrob(grobs=Plots, nrow = 1, ncol = 2)
Run Code Online (Sandbox Code Playgroud)

或者,等效地,

do.call(marrangeGrob, list(grobs=Plots, nrow = 1, ncol = 2))
Run Code Online (Sandbox Code Playgroud)