【问题标题】:GGplot multiple pages prints same first plots over and overGGplot 多页一遍又一遍地打印相同的第一个图
【发布时间】:2018-02-28 21:01:51
【问题描述】:

我正在尝试制作包含多个图的 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 出现之前(这太棒了!)或者没有解决我的问题。非常感谢。

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

【问题讨论】:

    标签: r ggplot2 facet-wrap ggforce


    【解决方案1】:

    问题只是您没有绘制每一页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()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-05-29
      • 1970-01-01
      • 2023-01-20
      • 2016-12-20
      • 2017-02-15
      相关资源
      最近更新 更多