如何将ggforce :: facet_grid_paginate的输出保存为一个pdf文件? [英] How to save output from ggforce::facet_grid_paginate in only one pdf?
问题描述
库(ggforce)
$ b $ for(i in 1:6){
ggplot(diamonds)+
geom_point(aes(克拉,价格),alpha = 0.1)+
facet_wrap_paginate(〜cut:clarity,ncol = 2,nrow = 2,page = i)
ggsave(paste0(〜/ diamonds_,i,.pdf))
}
正在生成预期的6个PDF文件:
最简单的方法是在一页pdf中输出6页吗?
我知道这可以通过报告
和 pdftools
包完成,但我想知道是否有更直接的方法来实现这一点。我希望ggforce为输出提供单页功能,但看起来情况并非如此? 解决方案
你甚至不需要使用 ggsave
,你可以把所有这些图放入一个 pdf
中:
pdf(〜/ diamonds_all.pdf)
for(i in 1:6){
print (ggplot(钻石)+
geom_point(aes(克拉,价格),alpha = 0.1)+
facet_wrap_paginate(〜cut:净度,ncol = 2,nrow = 2,page = i))
dev.off()
I'm using the ggforce package to generate facetted plots over several pages:
library(ggforce)
for(i in 1:6){
ggplot(diamonds) +
geom_point(aes(carat, price), alpha = 0.1) +
facet_wrap_paginate(~cut:clarity, ncol = 2, nrow = 2, page = i)
ggsave(paste0("~/diamonds_", i, ".pdf"))
}
which is generating the expected 6 PDF files:
What is the easiest way have the output in one single pdf with 6 pages?
I understand this can be done with the reports
and pdftools
packages, but I'm wondering if there's a more direct way to accomplish this. I'd expect ggforce to provide the functionality for the output to be single-paged, but it looks like that's not the case?
You don't even need to use ggsave
you can put all these plots into one pdf
by:
pdf("~/diamonds_all.pdf")
for(i in 1:6){
print(ggplot(diamonds) +
geom_point(aes(carat, price), alpha = 0.1) +
facet_wrap_paginate(~cut:clarity, ncol = 2, nrow = 2, page = i))
}
dev.off()
这篇关于如何将ggforce :: facet_grid_paginate的输出保存为一个pdf文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!