[R] lattice auto.key drop unused levels

Jacob Wegelin jacob.wegelin at gmail.com
Sat Oct 10 20:33:07 CEST 2009


The following code produces a legend ("key") that mentions the unused
levels of Block.

library(MEMSS)
xyplot(yield~nitro, subset=(Block=="I" | Block=="II"), data=Oats,
group=Block, auto.key=T)

and adding "drop.unused.levels=T" does not fix it. And in fact even
the following does not solve the problem:

 xyplot(yield~nitro, data=Oats[Oats$Block=="I" | Oats$Block=="II",],
group=Block, auto.key=T)

The following workaround solves it, but seems inelegant:

junk<-Oats[Oats$Block=="I" | Oats$Block=="II",]
junk$Block<-factor(as.character(junk$Block))
xyplot(yield~nitro, group=Block, data=junk, auto.key=T)

What is the elegant or "proper R thinking" way to do this? That is, I
want to get a key that only mentions the levels of Block that are used
in the plot.

Thanks

Jacob A. Wegelin
Assistant Professor
Department of Biostatistics
Virginia Commonwealth University
730 East Broad Street Room 3006
P. O. Box 980032
Richmond VA 23298-0032
U.S.A.
E-mail: jwegelin at vcu.edu
URL: http://www.people.vcu.edu/~jwegelin




More information about the R-help mailing list