1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
| library(gridExtra)
library(ggplot2)
pl <- lapply(1:20, function(.x) qplot(1:10, rnorm(10),
main=paste("plot", .x))+
labs(x="", y="", title=""))
lay <- rbind(c(1,2,3),
c(4,5,6),
c(7,8,9))
mg1 <- gridExtra::marrangeGrob(pl, nrow=3, ncol=3,
layout_matrix=lay,
left="y",
bottom="x",
top = bquote(paste("page", g, "of", npages, "\n", "\n", subtitle="Group1")))
mg2 <- gridExtra::marrangeGrob(pl, nrow=3, ncol=3,
layout_matrix=lay,
left="y",
bottom="x",
top = bquote(paste("page", g, "of", npages, "\n", "\n", subtitle="Group2")))
l <- list()
l[[1]] <- mg1
l[[2]] <- mg2
pdfPath = "./file.pdf"
pdf(file=pdfPath)
l[[1]]; l[[2]] # ça me donne un fichier pdf avec les plots mais je voudrais éviter de faire cela car si j'ai 10 groupes je n'ai pas envi de faire dix fois l[[1]], l[[2]], ..., l[[10]]
# unlist(l) # ça ne marche pas
# for(i in 1:length(l)){ l[[i]] } # ça ne marche pas
dev.off() |
Partager