Saving and exporting graphs

In this recipe, you will learn how to save and export our graphs to various useful formats.

How to do it...

To save a graph as an image file format such as PNG, we can use the png() command:

png("scatterplot.png")
plot(rnorm(1000))
dev.off()

The preceding command will save the graph as scatterplot.png in the current working directory. Similarly, if we wish to save the graph as JPEG, BMP, or TIFF, we can use the jpeg(), bmp(), or tiff() commands, respectively.

If you are working in Windows, you can also save a graph using the graphical user interface. First, make your graph, make sure that the graph window is the active window by clicking anywhere inside it, and then navigate to File | Save as | Png or the format of your ...

Get R: Data Analysis and Visualization now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.