输出到文件时光栅图分辨率差

Poor resolution of raster plot when output to file

我有一个相当高清晰度的全球地图栅格,想绘制到文件中,但似乎无法保持分辨率。绘制一个限制区域工作正常,但整个世界总是以降低分辨率结束,无论我使用什么方法。我在这里错过了什么吗?我以前经常输出高分辨率栅格而没有这个问题,但在这种情况下我无法确定原因。举例说明:

require(raster)
require(rworldmap)
data(countriesCoarse); worldmap = countriesCoarse
worldmap@data = data.frame(x = rep(1,length(worldmap))) # uniform vector
x_res = 3600; y_res = 1800
r0 <- raster(extent (-180,180,-90,90), ncol=x_res, nrow=y_res, crs=crs(worldmap))
rastermap <- rasterize(worldmap, r0, 'x') # ~ 2 mins

# small-area plot confirms raster's data resolution is ok
plot(rastermap, col='grey', xlim=c(-10,5), ylim=c(49,60), asp=T, axes=F, box=F, legend=F)

# the resolution is maintained for limited-area plot to file
png('plot0.png', width=x_res, height=y_res)
plot(rastermap, col='grey', axes=F, box=F, legend=F, xlim=c(-10,5), ylim=c(49,60), asp=T)
dev.off(); browseURL('plot0.png')

# but outputting global plots loses resolution..
par(mai=c(0,0,0,0))

png('plot1.png', width=x_res, height=y_res)
plot(rastermap, col='grey', axes=F, box=F, legend=F)
dev.off(); browseURL('plot1.png')

png('plot2.png', width=x_res, height=y_res)
image(rastermap, col='grey')
dev.off(); browseURL('plot2.png')

pdf('plot3.pdf', width=24, height=12)
plot(rastermap, col='grey', axes=F, box=F, legend=F)
dev.off(); browseURL('plot3.pdf')

require(Cairo)
CairoPNG('plot4.pdf', width=x_res, height=y_res)
plot(rastermap, col='grey', axes=F, box=F, legend=F)
dev.off(); browseURL('plot4.pdf')

这是文件输出图的通常输出方式(相同分辨率输出):

尝试?plot,阅读包raster提供的plot方法,找出maxpixels参数。然后,尝试

plot(rastermap, col='grey', axes=F, box=F, legend=F, maxpixels=1e8)

plot(rastermap, col='grey', axes=F, box=F, legend=F, maxpixels= x_res * y_res)

更快的是让图形设备进行光栅化:

require(Cairo)
CairoPNG('plot4.png', width=x_res, height=y_res)
plot(worldmap, col = 'grey', border = 'grey')
dev.off();
browseURL('plot4.png')