[R] More factor names in x axis, how?

Gabor Grothendieck ggrothendieck at myway.com
Tue Mar 9 07:23:23 CET 2004



You can omit the x axis from plot and create it yourself
using axis:

   plot(age ~ group, data=asd, xaxt="n")
   axis(1, 1:nlevels(group), levels(group))

---

Date:   Tue, 9 Mar 2004 17:09:23 +1300 (NZDT) 
From:   Richard A. O'Keefe <ok at cs.otago.ac.nz>
To:   <r-help at stat.math.ethz.ch> 
Subject:   [R] More factor names in x axis, how? 

 
I have some data which records, amongst other things,
age (recoded by me to be in months), and
drug group (a factor).
The drug group is a 2 digit number,
but there is no numeric relationship, and only 50 of the possible
groups occur

So

> asd <- read.table("asd.dat", header=TRUE)
> asd$group <- as.factor(asd$group)
> plot(age ~ group, data=asd)

gives me a series of boxplots which suggests that the age
distributions are worth examining further,
BUT while every factor level in the data is represented by
a tick mark on the x axis, only about half of the ticks
are labelled with the factor level. Because the factor
levels which occur are not consecutive integers, I cannot
tell what some of the tick marks represent.

There is enough room for all the factor levels to be printed,
but I cannot figure out how to make that happen. Shrinking
the labels with cex=0.5 (or even smaller) was the obvious thing
to try, but while making the labels bigger reduced the number of
factor levels shown, making the labels smaller didn't increase it.

I have checkd ?par and ?plot and ?plot.default and don't see anything
obvious.




More information about the R-help mailing list