Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does this image made by R have a spurious vertical white line in it?

Tags:

r

image

Sometimes, R draws white lines across an image plot for no apparent reason. Other plotting commands like lines() or contour() are not affected. This example is with x11, but it has happened with png() as well.

It can be fixed by changing the figure geometry. For example, a vertical white line can be eliminated by changing the width of the plot. But, this is not a real solution to the problem: many of my codes need to create publication-quality figures in scripts without supervision, often in packages I distribute to others.

Has anyone else encountered this? Does anyone know how to fix it? I'm using Ubuntu 16.04 64-bit with R version 3.3.1 (2016-06-21) -- "Bug in Your Hair", but have had this problem for years with many versions of R.

Here's an example code and image.

x = 4 * 0:1250
y = 4 * 0:1325
Z = matrix(rnorm(1251*1326), 1251)
image(x, y, Z)

enter image description here

like image 202
Vulcan Avatar asked Nov 12 '16 20:11

Vulcan


1 Answers

Try setting the logical useRaster option within the image function. As in:

x = 4 * 0:1250
y = 4 * 0:1325
Z = matrix(rnorm(1251*1326), 1251)
image(x, y, Z, useRaster = TRUE)

According to the details within ?image(),

Images for large ‘z’ on a regular grid are rendered more efficiently with 'useRaster = TRUE’ and can prevent rare anti-aliasing artifacts

See the man page for the full description.

like image 168
Alex Witsil Avatar answered Sep 18 '22 09:09

Alex Witsil