R: save multiple svg / png / tif charts

I am currently using pdf () to save multiple graphs on multiple pages.

I change the page simply to plot.new ().

Is it easy to get svg () and png () to do the same? Currently, only the latest chart is saved in the file.

If I cannot have it in the same file, can I have their self-generating files, such as: output.png, output2.png.

+4
source share
1 answer

If you look at the help pages ?png and ?svg , you will see that the default file names are "Rplot%03d.png" and "Rplot%03d.svg" respectively. Part of these names %03d means that every time a new chart is created, it automatically opens a new file, and part of the file name will be replaced by an incremental integer. Thus, the first file will be "Rplot001.png", and the next will be "Rplot002.png", etc.

If you don’t like the default file name, you can create your own and still insert the part to be replaced with an integer, for example, "myplots%02d.png" . % says that the number number starts here, 0 is optional, but says that 0 fill in the numbers (so you get 01, 02, ... rather than 1, 2, ...), this is usually preferable, so the sorting is done correctly (otherwise you can see the sorting as 1,10,11,2,3, ...), and the digit (3 by default, 2 in my example) is the number of digits if you create more 1000 plots, you must increase this to 4, if you know that you will not create 100, then 2 are fine (1 fine if you know that you will produce less than 10). And d is just an integer indicator.

+10
source

All Articles