R:使用marrangeGrob在空白首页中生成pdf结果 [英] R: Using marrangeGrob to make pdf results in blank first page

查看:340
本文介绍了R:使用marrangeGrob在空白首页中生成pdf结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作每个页面上带有多个图形的pdf文件,并且当我使用gridextra软件包中的marrangeGrob制作这些图形时,第一页始终是空白的.如何使绘图从第一页开始?这是一些示例代码:

I'm making some pdf files with multiple graphs on each page, and, when I use marrangeGrob from the gridextra package to make those graphs, the first page is always blank. How can I make the plots start on the first page? Here's some example code:

library(gridextra)
library(ggplot2)
data(iris)

Plotlist <- list()

Plotlist[[1]] <- ggplot(data = subset(iris, Species == "setosa"),
                         aes(x = Sepal.Width, y = Sepal.Length)) +
      geom_point()

Plotlist[[2]] <- ggplot(data = subset(iris, Species == "versicolor"),
                        aes(x = Sepal.Width, y = Sepal.Length)) +
      geom_point()

Plotlist[[3]] <- ggplot(data = subset(iris, Species == "virginica"),
                        aes(x = Sepal.Width, y = Sepal.Length)) +
      geom_point()

pdf("iris.pdf", width = 8.5, height = 11)
marrangeGrob(Plotlist, nrow = 2, ncol = 1)
dev.off()

pdf的第二页甚至在顶部说第1页,共2页",因此某处有些断开.

The 2nd page of the pdf even says at the top, "Page 1 of 2", so there's some disconnect somewhere.

推荐答案

我的猜测是,ggplot2中最近发生了一些更改,以调用网格函数来评估需要打开设备的网格单元.

My guess is that something's recently changed in ggplot2 to call a grid function to evaluate a grid unit that requires an open device.

您可以尝试此解决方法,

You can try this workaround,

glist <- lapply(Plotlist, ggplotGrob)
ggsave("iris.pdf", marrangeGrob(glist, nrow = 2, ncol = 1))

这篇关于R:使用marrangeGrob在空白首页中生成pdf结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆