7

When I plot a matrix with the image function as a TIFF file, I often get vertical or horizontal lines.

My matrix is of 150000 rows x 2000 columns, the lines also appears when plotting matrices of 150000 rows x 100 columns. The results are the same.

Where do the lines come from? Is this some sort of pixelated artifact? I get them almost all the time.

The matrix looks like this:

    V999 V1000 V1001 V1002 V1003 V1004 V1005 V1006 V1007 V1008 V1009 V1010
[1,]    1     4     0     0    15    15    15    15     8     0     1     0
[2,]    0     3    12     5    15    15    15     1    15     4     0     2
[3,]    0     0     0     3     6    15    15    15    15    15     0     3
[4,]    3     6    15    15    15    15    15     0     3    15    15     2
[5,]   15    15    15     0     3    15    15     2     1     5     8    11
[6,]    2     1     5     8    11    15    15    15     0     0     4     3


tiff("test.tiff", width=450, height=1100) 
image(t(mc),  col = col1, main="950-1500"
dev.off()

Any hints/comments will be much appreciated.

enter image description here

Jilber Urbina
  • 58,147
  • 10
  • 114
  • 138
Benoit B.
  • 11,854
  • 8
  • 26
  • 29
  • Have you tried other formats, like jpeg, png, pdf? Do these artifacts still come up? – Roman Luštrik Oct 11 '12 at 12:42
  • 1
    I have tried PNG add those lines come up as well. I can't do PDF really as the file size is quite large (500Mo), and then opening the file becomes challenging. – Benoit B. Oct 11 '12 at 13:04
  • I'm pretty sure this is an artifact of mapping the bins to pixels. Try mapping subsets of the heatmap at high resolution (i.e. x= 0.48:0.52) at high enough resolution that there are >5 pixels per bin. If they go away, you have a pixel artifact. If not, you've got a bigger problem. – Drew Steen Oct 11 '12 at 13:59
  • If you do not need the axes, (rtiff)[http://cran.r-project.org/web/packages/rtiff/] may help: it writes pixmaps directly into tiff images, so you have 1:1 pixel correspondence. – cbeleites unhappy with SX Oct 11 '12 at 15:25
  • 1
    As for the tiff, png, etc. devices it would be really nice to have a method to set the resolution to get such a 1:1 correspondence between matrix elements and pixels... – cbeleites unhappy with SX Oct 11 '12 at 15:26
  • @cbeleites if one moves the matrix to a `RasterLayer` object, you can set the resolution, aiding in mapping matrix elements to pixels. @Benoit B., can you provide us with a small reproducible example? – Roman Luštrik Oct 22 '12 at 09:47

1 Answers1

1

You're seeing an aliasing artifact from the x11() display. You can try dragging the window to make it bigger or smaller and eventually you'll find a window size height and width that is compatible with your desired resolution.

kith
  • 5,486
  • 1
  • 21
  • 21