R GGplot多页反复打印相同的第一个绘图

R GGplot多页反复打印相同的第一个绘图,r,ggplot2,facet-wrap,ggforce,R,Ggplot2,Facet Wrap,Ggforce,我试图制作多个绘图的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

我试图制作多个绘图的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()

pg问题很简单,你没有画每一页
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()

pg问题很简单,你没有画每一页
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()
pg