Generate many plots at once in R
1
0
Entering edit mode
4.6 years ago
giegie • 0

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 • 550 views
ADD COMMENT
2
Entering edit mode

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.

ADD REPLY
1
Entering edit mode
4.6 years ago
zx8754 12k

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()
ADD COMMENT

Login before adding your answer.

Traffic: 1283 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6