In a number of scripts I first develop a graph on screen, and then need to save it as several file formats with particular height/width/resolution. Using png()
, pdf()
, svg()
, ... to open a device, and then dev.off()
to close it, I'm forced to put all the device open calls into my script and comment them out & re-run the code one device at a time.
I do know that for ggplot graphics, ggsave()
makes this easier.
Is there any thing I can do to simplify this for base-R and lattice graphics?
One example:
png(filename="myplot.png", width=6, height=5, res=300, units="in")
# svg(filename="myplot.svg", width=6, height=5)
# pdf(filename="myplot.pdf", width=6, height=5)
op <- par() # set graphics parameters
plot() # do the plot
par(op)
dev.off()