【发布时间】:2017-09-22 05:25:49
【问题描述】:
我需要修改一个绘图的一些注释,所以我必须保存 ggplot2 绘图并做
ggplot_build(plot.obj)
然后用它绘制
plot(ggplot_gtable(ggplot_build(plot.obj)))
问题是,当我将它保存在这样的 pdf 中时
pdf(file="test.pdf")
plot(ggplot_gtable(ggplot_build(plot.obj)))
dev.off()
生成的 pdf 在绘图页之前有一个空白页...我怎样才能避免这种情况?
检查这个 MWE
data(iris)
library(ggplot2)
box <- ggplot(data=iris, aes(x=Species, y=Sepal.Length)) +
geom_boxplot(aes(fill=Species)) +
ylab("Sepal Length") + ggtitle("Iris Boxplot") +
stat_summary(fun.y=mean, geom="point", shape=5, size=4)
box2 <- ggplot_build(box)
#I do stuff here
pdf(file="test.pdf")
plot(ggplot_gtable(box2))
dev.off()
问题是如何在没有空白页的情况下使用 ggplot_gtable 制作 pdf?
【问题讨论】: