To save a plot to an image file in R, follow the below steps.
- Call a function to open a new graphics file, such as png(), jpg(), or pdf().
- In the next step, call the plot() function to generate the graphics image.
- At last, call the dev.off() function to close the graphics file.
If you don’t provide an external path, then it will save in your current directory.
Example
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)")
dev.off()
Output
You check the downloaded png file inside your current directory.
That’s it.

Krunal Lathiya is a Software Engineer with over eight years of experience. He has developed a strong foundation in computer science principles and a passion for problem-solving. In addition, Krunal has excellent knowledge of Data Science and Machine Learning, and he is an expert in R Language.