0

我正在尝试制作多个图的 pdf,但 pdf 只会打印前 n 个图。我正在使用 ggforce::facet_wrap_paginate。下面是我写的代码。如果有人对为什么我只得到前 6 个地块有任何建议,我会很高兴?我也尝试过使用 PNG,但我遇到了同样的问题。完成后,我期待 20-30 页(大约 160 个图)之间的 pdf。所以你可以理解我只有6个情节的挫败感......

pg <- ceiling(
  length(levels(Tidy$Region)) / 6
)

pdf("attempt3001.pdf")
for(i in seq_len(pg)){
  print(ggplot(Tidy, aes(x=Year, y=Value / 1000, group=Country, color=Status))+
      geom_line()+
      theme_classic()+
      facet_wrap_paginate(~Region, nrow = 3, ncol = 2, page = 1, scales = "free"))
}
dev.off()

我在堆栈上看到过类似的问题,但它们是在 facet_wrap_paginate 出现之前(这太棒了!)或者没有解决我的问题。提前谢谢了。

这个问题是我模拟当前代码的问题。我希望我可以评论那个,但我没有声誉哈哈。

4

1 回答 1

2

问题只是你没有画每一页i,而只画了第一页。在您的代码中替换page = 1为。page = i

pg <- ceiling(
 length(levels(Tidy$Region)) / 6
)

pdf("attempt3001.pdf")
for(i in seq_len(pg)){
  print(ggplot(Tidy, aes(x=Year, y=Value / 1000, group=Country, color=Status)) +
         geom_line() +
         theme_classic() +
         facet_wrap_paginate(~Region, nrow = 3, ncol = 2, page = i, scales = "free"))
}
dev.off()
于 2018-02-28T21:37:48.043 回答