[R] Trouble plotting with factor
Martin Maechler
maechler at stat.math.ethz.ch
Sat Jan 31 14:34:33 CET 2004
>>>>> "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
More information about the R-help
mailing list