[英]GGplot multiple pages prints same first plots over and over
我正在嘗試制作多個圖的pdf,但是pdf只打印前n個圖。 我正在使用ggforce :: facet_wrap_paginate。 以下是我編寫的代碼。 如果有人對我為什么只得到前6個地塊有任何建議,我會很樂意。 我也嘗試過使用PNG進行此操作,但是我遇到了同樣的問題。 完成后,我期望pdf介於20到30頁之間(約160幅圖)。 所以你只用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出現之前(真是太神奇了!),或者沒有解決我的問題。 提前謝謝了。
這個問題是我根據當前代碼建模的。 我希望我可以對此發表評論,但是我沒有聲譽哈哈。
問題是,您只繪制了第一頁而不是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()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.