This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Generate many plots at once in R

I have a function which generates a plot: function(x, y,"name")

I would like to generate as many plots as "names" present in character z

z

[1] "Bzw1"          "Dnajc1"        "Ppig"          "Prex1"         "Dpm1"          "Prpf38b"      
[7] "Snrnp70"       "Spty2d1"       "Cbl"           "Anxa2"         "Ggnbp2"        "Cltc"

and save all of them in a working directory.

r

What have you tried? The only thing that makes this question related to bioinformatics is that the names look like mouse genes. Otherwise, this is a question that should be on stackoverflow.

1 answer

Relevant reading: ggplot facets, patchwork package, cowplot package, Google for "r multiple plots"

Here is an example using base plot. This outputs one pdf file one plot on each page.

foo <- function(x) {
  plot(mtcars[, x], main = x)  
}

pdf("allPlots.pdf")
lapply(colnames(mtcars), foo)
dev.off()

Log in to answer this question.