marrangeGrob giving error for nrow

醉酒当歌 提交于 2019-12-07 09:30:07

问题


I'm trying to create a bunch of ggplot2 plots using a for loop and then saving them on a multi-page pdf document, and I'm having trouble with marrangeGrob. Here's some example 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've used similar versions of the do.call(marrangeGrob... line in the past and had them work, but now, I get this error when I try to execute that line: Error: nrow * ncol >= n is not TRUE. The fact that code similar to this used to work makes me think that something in one of these packages has since been updated. Any suggestions on how to fix this?


回答1:


The syntax has changed a little with the new grobs argument. You should use

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

or, equivalently,

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


来源:https://stackoverflow.com/questions/33352508/marrangegrob-giving-error-for-nrow

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!