Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
There are two ways to output to PNG bitmap files. One method is
to open the PDF graphics device with png(), make the
plots, then close the device with dev.off(). This method
works for most graphics in R, including base graphics and grid-based
graphics like those created by ggplot2 and lattice:
# width and height are in pixelspng("myplot.png",width=400,height=400)# Make plotplot(mtcars$wt,mtcars$mpg)dev.off()
For outputting multiple plots, put %d in the filename. This will be replaced with
1, 2, 3, and so on, for each subsequent plot:
# width and height are in pixelspng("myplot-%d.png",width=400,height=400)plot(mtcars$wt,mtcars$mpg)print(ggplot(mtcars,aes(x=wt,y=mpg))+geom_point())dev.off()