【发布时间】:2019-04-11 16:31:13
【问题描述】:
我正在尝试使用 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)
我过去曾使用过类似版本的 do.call(marrangeGrob... 行并让它们工作,但现在,当我尝试执行该行时出现此错误:Error: nrow * ncol >= n is not TRUE。与此类似的代码过去可以工作的事实使我认为其中一个软件包中的某些内容已经更新。对于如何解决这个问题,有任何的建议吗?
【问题讨论】:
-
ggsave("out.pdf", marrangeGrob(Plots, nrow = 1, ncol = 2))可能是由于最近的变化 -
这对我不起作用。我收到一个错误,
plot should be a ggplot2 plot. -
好的...几个选项;
pdf("out.pdf"); marrangeGrob(Plots, nrow = 1, ncol = 2) ; dev.off()或升级ggplot2,它现在已经删除了对 ggplot2 对象的检查,或者使用从 SO..ggsave <- ggplot2::ggsave; body(ggsave) <- body(ggplot2::ggsave)[-2]学到的 ahack,如果不升级 -
ggplot2 已经是最新的了,但是
pdf("out.pdf"; marrangeGrob...等效果很好!谢谢! -
啊好的...重新 ggplot2 ,我想我可能有来自github的开发版本
标签: r ggplot2 gridextra r-grid