如何在 R 中保存绘图图像? [英] How do I save plot images in R?

查看:65
本文介绍了如何在 R 中保存绘图图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从一个非常大的向量(大小为 10^7)创建了一个图.将绘图保存为 pdf 文件的通常方法的问题在于,pdf 文件是一个大约 10MB 的非常大的文件.对于简单的时间序列图,我不想要这么大的尺寸.我如何保存绘图,使其大小足够小,最多 100 千字节?

I have created a plot from a very large vector (magnitude of 10^7). The problem with the usual way of saving the plot as a pdf file is that the pdf file comes out as a very large file of around 10MB. I don't want such a large size for a simple time series plot. How do I save the plot such that the size is small enough to be at most 100kilobytes?

推荐答案

baptiste 是正确的,他们建议使用 png 来制作漂亮的光栅类型图.相对于Jdbaba的建议复制打开的设备,我建议你直接调用png()设备.这将节省大量时间,因为您不必先在单独的设备窗口中加载绘图,如果数据集很大,加载时间可能会很长.

baptiste is on the right track with their suggestion of png for a nice raster type plot. In contrast to Jdbaba's suggestion of copying the open device, I suggest that you make a call to the png()device directly. This will save a lot of time in that you won't have to load the plot in a separate device window first, which can take a long time to load if the data set is large.

#plotting of 1e+06 points
x <- rnorm(1000000)
y <- rnorm(1000000)
png("myplot.png", width=4, height=4, units="in", res=300)
par(mar=c(4,4,1,1))
plot(x,y,col=rgb(0,0,0,0.03), pch=".", cex=2)
dev.off() #only 129kb in size

有关 png 设备的其他设置,请参阅 ?png.

see ?png for other settings of the png device.

这篇关于如何在 R 中保存绘图图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆