ploting artefact with points over raster

那年仲夏 提交于 2019-12-01 04:27:42

If you plot directly with the RasterLayer method for plot the resize problem does not occur.

## gives an error, but still plots 
raster:::.imageplot(shrunk)
points(shrunk.coords, pch = ".")

So it must be something in the original plot call before the .imageplot method is called.

 showMethods("plot", classes = "RasterLayer", includeDefs = TRUE)

It does occur if we call raster:::.plotraster directly, and this is the function that calls raster:::.imageplot:

raster:::.plotraster(shrunk, col = rev(terrain.colors(255)), maxpixels = 5e+05)
points(shrunk.coords, pch = ".")

It is actually in the axis labels, not the image itself. See with this, this plots faithfully on resize:

 raster:::.imageplot(shrunk)
 abline(h = c(-80, 80), v = c(-80, 80))

But do it like this, and the lines are no longer at [-80, 80] after resize:

plot(shrunk)
abline(h = c(-80, 80), v = c(-80, 80))

So it is actually the points plotted after the raster that are showing incorrectly: the plot method keeps the aspect ratio fixed, so widening the plot doesn't "stretch" out the raster circle to an ellipse. But, it does something to the points that are added afterwards so the calls to par() must not be handled correctly (probably in raster:::.imageplot).

Another way of seeing the problem is to show that axis() does not know the space being used by the plot, which is the same problem you see when overplotting:

plot(shrunk)
axis(1, pos = 1)

When you resize the x-axis length the two axes are no longer synchronized.

Because you have a raster, try replacing plot() with image(). I had the same problem but this solved it for me.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!