[R] Trouble plotting with factor

Marc Schwartz MSchwartz at medanalytics.com
Sat Jan 31 18:20:18 CET 2004


On Sat, 2004-01-31 at 07:34, Martin Maechler wrote:
> >>>>> "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>>

Thanks Martin.

> 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))


Right. I had actually started to use that approach (which I have used in
the past for plot(), etc.). I must have had a transient loss of blood
flow to the brain, as I for some reason (uncommented in my code), I
decided to use 'axes = FALSE'.  Either that, or I was asleep at the
keyboard and my fingers were on autopilot....  :-)

Thanks for pointing that out Martin.

Best regards,

Marc




More information about the R-help mailing list