Saving multiple ggplots from ls into one and separate files in R

后端 未结 4 601
独厮守ぢ
独厮守ぢ 2020-12-01 00:08

I have several ggplots as objects on my ls. I want to save them as separate files (although I would also be interested to know how to save them all under 1 big file). I have

4条回答
  •  生来不讨喜
    2020-12-01 00:56

    If the plots p1, p10, etc. already exist, and you want them saved as p1.pdf, etc., then I think this should do it:

    lapply(plots,function(x){ggsave(file=paste(x,"pdf",sep="."),get(x))})
    

    ggsave(...) has a number of arguments for specifying the dimensions and format of the output file.

提交回复
热议问题