我正在制作一些每页包含多个图形的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页”,因此某些地方存在不一致。
Plotlist <- lapply(split(iris, iris$Species), function(S){ ggplot(S, aes(x = Sepal.Width, y = Sepal.Length)) + geom_point() })
- eipi10