How to Save a Plot to an Image File

To save a plot to an image file in R, follow the below steps.

  1. Call a function to open a new graphics file, such as png(), jpg(), or pdf().
  2. In the next step, call the plot() function to generate the graphics image.
  3. At last, call the function to close the graphics file.

If you don’t provide an external path, then it will save in your current directory.


png(filename = "mp.png", width = 625, height = 400)

plot(pressure, col = "red", pch = 19, type = "b",
 main = "Vapor Pressure of Mercury",
 xlab = "Temperature (deg C)",
 ylab = "Pressure (mm of Hg)")



You check the downloaded png file inside your current directory.

That’s it.

Leave a Comment