At some point, you will have to save your plot as a picture file. There are two simple options:

The “Export” button

In Rstudio, in the menu bar just above the plot itself, you will find a button called Export as illustrated in the picture below:

If you click on it, you will have the possibilty to save as image or save as pdf. In all cases, a dialog box pops up and gives you plenty of options to define the dimensions, target folder, file name, file type,etc. The screenshot below illustrates the dialog window that appears after you pressed save as image. You just have to fill up all the necessary fields and click Save.



The function ggsave()

If after a few hours coding your plot with care and patience, you still have some energy for coding a bit more, then you may save your plot with the function ggsave(). By default, the function saves the last plot that has been produced into a file which name must be specified. The simplest code is thus something like this:

ggsave("test.png")
## Saving 7 x 5 in image

Rstudio tells you that the image has been produced and indicates the dimensions (in inches). This image has been placed by default in your working directory.

If you want to have better control over the file properties, you may add a series of arguments to ggsave(). Some useful arguments are:

Finally the filename should also contain the extension that you wish (.pdf, .jpg, .jpeg, .png, .svg, .tiff, .eps, etc).

ggsave("test.jpg", dpi = 300, width = 20, height = 20, units = "cm")