On Sat, Oct 10, 2009 at 8:51 PM, Peter Ehlers <ehl...@ucalgary.ca> wrote:
> 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.

So the answer seems to be that there is no way to drop the levels
without bypassing the "subset" argument.

The following creates the desired effect:

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

whereas dropping levels in the "group" argument does not create the
desired effect

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

Jacob Wegelin

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

______________________________________________
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