Skip to content
Back to formatted view

Raw Message

Message-ID: <16411.44777.144608.186713@gargle.gargle.HOWL>
Date: 2004-01-31T13:34:33Z
From: Martin Maechler
Subject: Trouble plotting  with factor
In-Reply-To: <1075515592.31290.528.camel@localhost.localdomain>

>>>>> "Marc" == Marc Schwartz <MSchwartz at medanalytics.com>
>>>>>     on Fri, 30 Jan 2004 20:19:52 -0600 writes:

  <<excellent nicely told help text for Paul Johnson>>


I want to comment on the following because it's 
"not quite optimal", and still is recommended on-and-on ....

    Marc> # Now use matplot() to plot each column

    Marc> # Do not plot the axes
    Marc> matplot(df, type = "l", axes = FALSE,
    Marc>         xlab = "Age Group", ylab = "Proportion DL Ownership")

    Marc> # Create the X axis, specifying 15 tick marks 
    Marc> # and using rownames(df) as the labels
    Marc> axis(1, at = 1:nrow(df), labels = rownames(df))

    Marc> # Now draw the Y axis with defaults
    Marc> axis(2)

    Marc> # Put a box around the whole thing
    Marc> box()

More elegant is not to set axes = FALSE (and having to add
axis(2) and box() later) but to use  xaxt = 'n'  {only
suppressing x-axis}, i.e., instead of the above 4 statements,
only two :

 matplot(df, type = "l", xaxt = "n", # do not plot the 'x' axis
         xlab = "Age Group", ylab = "Proportion DL Ownership")

 # Create the X axis, specifying 15 tick marks 
 # and using rownames(df) as the labels
 axis(1, at = 1:nrow(df), labels = rownames(df))


Martin