[R] Problems with graphical devices, e.g., png(), pdf(): blurry graphical output

Martyn Plummer plummer at iarc.fr
Wed Dec 17 12:06:37 CET 2008


The artefacts that you see are a normal result of using bitmap graphics
devices.  I have tried to explain these below:

I have looked at your figures in Eye of Gnome, with anti-aliasing turned
off (Menu Edit/Preferences; Tab "Image View"; option "Smooth images when
zoomed").  I recommend that you do the same.

> png('test.png',antialias='none') # type is 'cairo'
> plot(1:10)
> dev.off()
> ## result: no fuzziness at all but the box is missing
> ## the top and left border lines
> ## http://www.piccdrop.com/images/1229495388.png

Cairo works in real (double precision) coordinates. But the line must be
converted to bitmap to be displayed. When this is done without
anti-aliasing, it is quite possible for a thin horizontal or vertical
line to pass in-between the points on a grid that are sampled to form
the bitmap image, and hence disappear.

> png('test.png') # type is 'cairo'
> plot(1:10)
> dev.off()
> ## result: box lines fuzzy at top and left, and appears 
> ## darker and thicker where the axes are overplotted
> ## http://www.piccdrop.com/images/1229495327.png

With anti-aliasing, a horizontal or vertical line may appear as a 1
pixel wide black line, but is more likely to appear as a 2 pixel wide
grey line.  When two such grey lines are over-plotted, they will create
a darker grey line. The overplotted line also appears thicker, but this
is an optical illusion.

> png('test.png',type='Xlib')
> plot(1:10)
> dev.off()
> ## result: no fuzziness at all and no lines missing
> ## http://www.piccdrop.com/images/1229495428.png

Xlib works in integer coordinates. When a line is plotted in Xlib, the
start and end coordinates are cast to integer before plotting. Hence
horizontal/vertical lines will always appear, with a width of 1 pixel
and overplotting does not change the appearance of a line.

Martyn

On Wed, 2008-12-17 at 01:36 -0800, Y-H Chen wrote:
> On Wed, Dec 17, 2008 at 12:54 AM, Prof Brian Ripley
> <ripley at stats.ox.ac.uk> wrote:
> > Your PDF problems indicate a broken viewer.  How were you viewing PDF?
> 
> You are absolutely correct about the PDF files; I've since checked the
> PDF files in other viewers and have not been able to reproduce the
> problem. There was definitely something wrong with my default viewer.
> I am most certainly embarrassed.
> 
> As for the PNG files: I've viewed the PNG files on two different
> systems, in various viewers. On a Fedora system in Eye of Gnome,
> Firefox, Epiphany, GIMP, and gThumb. And, on a Windows system in
> Paint, Firefox, Internet Explorer, and GIMP. I see blurriness in all
> of these viewers for all of the files I originally claimed difficultly
> with (as mentioned in my last message, I don't see blurriness in the
> images produced via type='Xlib'). I'll do more tests on other systems
> once I get the chance, but that's what I see at the moment. The files
> are linked to in the text file I provided, and you are all invited to
> check those out if you are interested.
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

-----------------------------------------------------------------------
This message and its attachments are strictly confidenti...{{dropped:8}}



More information about the R-help mailing list