[英]How to get plots in several pdf pages using ggplot2
我需要幫助將圖形處理成多個 pdf 頁面。 這是我當前的代碼:
file <- read.csv(file="file.csv")
library(ggplot2)
library(gridExtra)
library(plyr)
gg1 <- ggplot() +
geom_line(aes(x=TIME, y=var1, colour = "z1"), file) +
geom_line(aes(x=TIME, y=var2, colour = "z2"), file) +
geom_point(aes(x=TIME, y=var3), file) + facet_wrap( ~ ID, ncol=5)+
xlab("x") +
ylab("Y") +
ggtitle(" x ") + scale_colour_manual(name="Legend",
values=c(z1="red", z2 ="blue")) + theme(legend.position="bottom")
gg10 = do.call(marrangeGrob, c(gg1, list(nrow=4, ncol=4)))
ggsave("need10.pdf", gg10)
這是創建的圖像,沒有拆分我的圖像
我希望有一個代碼來在多個頁面中以 4 x 4 布局獲取我的圖。 我的代碼的最后兩行需要調整,我不知道如何自己修復。
ggplus
包裝器似乎ggplus
您的需求。 我從您的原始代碼塊中更改了以下代碼塊中的一些內容: facet_wrap
被注釋掉,並且file
被移動到ggplot
以便不必在每個geom_*
重新指定geom_*
:
gg1 <- ggplot(file) +
geom_line(aes(x=TIME, y=var1, colour = "z1")) +
geom_line(aes(x=TIME, y=var2, colour = "z2")) +
geom_point(aes(x=TIME, y=var3)) +
# facet_wrap( ~ ID, ncol=5) +
xlab("x") +
ylab("Y") +
ggtitle(" x ") +
scale_colour_manual(name="Legend",
values=c(z1="red", z2 ="blue"),
labels=c("X","Y")) +
theme(legend.position="bottom")
devtools::install_github("guiastrennec/ggplus")
library(ggplus)
pdf("need10.pdf")
gg10 <- facet_multiple(plot=gg1, facets="ID", ncol = 4, nrow = 4)
dev.off()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.