我正在制作一些每页上有多个图形的 pdf 文件,并且当我使用 gridextra 包中的 marrangeGrob 来制作这些图形时,第一页始终是空白的。如何使绘图从第一页开始?这是一些示例代码:
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 页”,因此某处存在一些脱节。
我的猜测是 ggplot2 最近发生了一些变化,调用网格函数来评估需要开放设备的网格单元。
您可以尝试这个解决方法,
glist <- lapply(Plotlist, ggplotGrob)
ggsave("iris.pdf", marrangeGrob(glist, nrow = 2, ncol = 1))
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)