The key will show the levels of the 'groups' factor. So you will
have to ensure that the factor fed to groups has the levels
that you want displayed. ?xyplot explicitly states that
drop.unused.levels will NOT do that for you.

(Didn't Deepayan just answer something like this?)

 -Peter Ehlers

Jacob Wegelin wrote:
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: jwege...@vcu.edu
URL: http://www.people.vcu.edu/~jwegelin

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.



______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to