RScript: how to get the plots saved into multiple files (say png) rather than saved into the Rplots.pdf?
Question
I use RScript in Windows and by default it saves the plots into the pdf file Rplots.pdf
, one plot per page.
I would like to get each plot saved into an image file like a .png
, is it possible?
Solution
To save your plots as a png
file, the general idea is:
png("spam.png")
plot(...)
dev.off()
similar functions are jpeg
and tiff
. Wrap all your plots in such calls to png
to save the plots to specific names. Adding png()
at the top of the script will save all plots in different png files: Rplot001.png
, Rplot002.png
. I would however try and give meaningful names to the plots.
Using Cairo devices, you can use savePlot
. When you plot with ggplot2
, the best way imo to save a plot is using ggsave
.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow