Saving R Plots as Images

In R language, you can use the following code to save the plotted graph as an image:

# 设定图片保存路径和文件名
file_path <- "D:/plot.jpg"

# 保存绘制的图为jpg格式图片
jpeg(file_path)
plot(x, y, type="l")
dev.off()

In the code above, the path and file name for saving the image are first set, then the plot is saved as a jpg format image using the jpeg() function, and finally the plot device is closed using dev.off() function. You can also replace the jpeg() function with other functions like png(), pdf(), etc., to save the image in different formats.

bannerAds