I am trying to use lapply to plot 3 graphs using ggplot package for every file I am looping through.
Here is my code:
pdf("outfile.pdf")
lapply(files,function(x){
a <- basename(x)
a <- gsub("*_junc_with_type_genename_fpkm.txt","",a)
d <- fread(x,drop=c(1:4,6,7))
setnames(d, c("junc_counts", "TYPE","gene_name","sgd_name","fpkm"))
p1 <- ggplot(...)
p2 <- ggplot(...)
p3 <- ggplot(...)
grid.arrange(p1,p2,p3)
})
dev.off()
So if there are 5 input files, I want to plot 15 graphs(3 for each file: p1,p2,p3) on separate pages in the pdf output file.
Right now 3 graphs on one page are being plotted by the above code.