本文介绍了marrangeGrob给nrow给错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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)

我使用了类似版本的 do .call(marrangeGrob ... 在过去的行,并让他们工作,但现在,当我尝试执行该行时出现此错误:错误:nrow * ncol> ; = n不是TRUE 。与之类似的代码让我觉得这些软件包中的某些内容已经被更新了,对于如何解决这个问题有什么建议?

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?

推荐答案

语法有cha与新的 grobs 参数稍微有点不同。您应该使用

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))

这篇关于marrangeGrob给nrow给错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-01 22:13