Export High-Res Images in R: Complete Guide

In R language, you can adjust the resolution of plots using parameters to obtain higher quality images. Specifically, you can save images as PDF format and specify the resolution using the pdf() function, or save them as PNG format and set the resolution using the png() function. Here is an example code:

# 生成一个简单的散点图
x <- rnorm(100)
y <- rnorm(100)
plot(x, y)

# 将图像保存为PDF格式并设置分辨率
pdf("my_plot.pdf", width = 8, height = 6, pointsize = 12)
plot(x, y)
dev.off()

# 将图像保存为PNG格式并设置分辨率
png("my_plot.png", width = 800, height = 600, res = 300)
plot(x, y)
dev.off()

In the code above, the pdf() function is used to save the image in PDF format, and the png() function is used to save it in PNG format. Both functions allow for setting the width, height, and resolution of the image. After calling the plot() function, use the dev.off() function to close the device and save the image. By adjusting these parameters, you can achieve a higher resolution image.

bannerAds