Home > Software design >  Save graphs from lists with mapply [R]
Save graphs from lists with mapply [R]

Time:10-03

I would like to save multiple graphs from the large list df (list containing lists). with the following code I can generate the graph

require(oce)
mapply(function(dat, nm) { 
  plotProfile(dat, xtype="temperature",
col.temperature="black") 
  },
dat = df, nm = names(df))

But now I would like to extract the graphs in one pdf (if possible). With something like

pdf("~path/*.pdf")
#the code
dev.off()

CodePudding user response:

If you can run and plot the function, you can just simply put it after the pdf call and it'll save them all in the pdf,

pdf("~path/*.pdf")
mapply(function(dat, nm) { 
    plotProfile(dat, xtype="temperature",
col.temperature="black") 
},
dat = df, nm = names(df))
dev.off()

Also, it'll be nice to have a reprex containing the dataframe to test it out.

  • Related