AW: [R] How to improve the quality of curve/line plots?

(Ted Harding) Ted.Harding at nessie.mcc.ac.uk
Fri Sep 24 11:55:08 CEST 2004


On 24-Sep-04 Wolf, Michael wrote:
> Thanks for the tip using a smoothing technique before plotiing in order
> to get a curve instead of a line connecting the observations.
> 
> But that's not the solution for my main problem with the "unclean" line
> plot. In order to show my problem let's take this simple example:
> 
>> xval <- c(1, 2, 3, 4, 5, 6, 7, 8)
>> yval <- c(10, 30, 40, 50, 70, 90, 100, 110)
>> plot (xval, yval, type="l")
> 
> If you look to the result in the graphic window you will see that the
> line seems to exist of many points between the observations; e. g.
> between xval=1 and xval=2 the line contains 8 or more sublines.
> Perhaps, you can also observe a break of the line at xval=4. That's
> what I call an "unclean line". 
> 
> Even if you try to export the plot with the png command you can observe
> the same phenomenon. The line has not an exact appearance like Excel
> diagram plots. If there are no other techniques to get better line
> plots it seems to be a problem of the graphic output!? 

You might describe it in this way! The fundamental issue is that on
screen the display is generated by assigning different colours to
each of an array of tiny panels, the "pixels". The actual size of
a pixel depends on the hardware, i.e. your monitor, but typically
it is of the order of 1/100 inch (i.e. 1/4 mm). This size is quite
visible and can give a ragged or "stepped" appearance to things
which you might expect to show as smooth curves or lines. This
effect is also different between CRT monitors (where the pixel
is illuminated by a scanning electon beam) and TFT monitors where
each pixel is a physical entity and is activated under electronic
control. TFT pixels are more sharply defined then CRT pixels, and
have a clearly visible square shape. Thus, for instance, the
representation of letters on the screen (e.g. "c" or "C") will
also show rough edges if looked at closely. CRT pixels are a bit
"fuzzy" at the edges and corners, and so look smoother.

When a plot is sent to the screen, the pixel which is turned on
is (or should be) the one which is nearest to the mathemtical point
in the ideal plot. This inevitably results in a somewhat "broken"
appearance such as you describe. The same applies to any bit-mapped
representation.

One solution for printing purposes is to save the plot in any
vector-graphic format (PostScript or Windows Metafile), where lines
and curves are mathematically defined and when rendered (on, e.g. a
printer which has pixels of the order of 1/1200 inche or 1/300 mm,
or smaller) give results which, to the naked eye, look much smoother
since the dots are much smaller (also, printer "pixels" are often
approximately circles rather than squares). Nevertheless, you can
still detect the roughness if you use a strong magnifying glass.

On screen, there is a rendering technique called "anti-aliasing".
This means that as well as activating a given pixel as above,
neighbouring pixels are also activated at lower intensities,
so that each "real" pixel is surrounded by a halo of "false"
pixels at lower intensity, thereby artifically fuzzing the edges
and giving the eye the impression of smoothness.

It may be (though I don't know) that this is what Excel does,
thereby giving you the impression that the lines are "clean"
rather than "dirty".

But the fundamental message is that every image which is rendered
on a device based on bit-mapping is necessarily "dirty", even if
optical trickery gives the opposite impression!

Best wishes,
Ted.


--------------------------------------------------------------------
E-Mail: (Ted Harding) <Ted.Harding at nessie.mcc.ac.uk>
Fax-to-email: +44 (0)870 094 0861   [NB: New number!]
Date: 24-Sep-04                                       Time: 10:55:08
------------------------------ XFMail ------------------------------




More information about the R-help mailing list