在R中输出高分辨率的fill.contour数字

时间:2014-07-24 22:55:48

标签: r plot png

我正在尝试将我的filled.contour图保存为Rstudio中的高分辨率(> 600dpi)piture(png,jpeg ....)。 但是,当我在Rstudio的界面中使用“导出”功能时,分辨率非常低(数字仅为20kb左右)。

然后我尝试使用“PNG”命令保存我的情节,但我失败了。

我想问有没有人知道怎么做到这一点?

非常感谢你的帮助!

1 个答案:

答案 0 :(得分:0)

我认为你想要这样做以在图像以非常大的比例渲染时保持分辨率。要使用png(...)函数实现此目的,您必须设置大小(heightwidth参数)以及ppi(res参数)中的分辨率。因此,下面的代码创建一个16 x 8.5英寸图像的png文件,600 ppi或6600 X 5100像素。该文件为435KB。

# open the  png graphics device
png("volcano.png",res=600,height=8.5,width=11,units="in")

## the following is taken verbatim from the filled.contour(...) documentation
x <- 10*1:nrow(volcano)
y <- 10*1:ncol(volcano)
filled.contour(x, y, volcano, color=terrain.colors,
               plot.title = title(main = "The Topography of Maunga Whau",
                                  xlab = "Meters North", ylab = "Meters West"),
               plot.axes = { axis(1, seq(100, 800, by = 100))
                             axis(2, seq(100, 600, by = 100)) },
               key.title = title(main = "Height\n(meters)"),
               key.axes = axis(4, seq(90, 190, by = 10)))  # maybe also asp = 1
mtext(paste("filled.contour(.) from", R.version.string),
      side = 1, line = 4, adj = 1, cex = .66)
##

# close the graphic device
dev.off()

如果您希望以大于11 X 8.5的物理尺寸渲染它,则需要以适当的大小生成png。