[R-sig-eco] omit levels from boxplots
Ben Bolker
bbolker at gmail.com
Thu Jan 6 18:29:00 CET 2011
On 11-01-06 12:16 PM, Jarrett Byrnes wrote:
> Ah, so, you have factors that are no longer present in the data. I
> use a quick function I wrote called purgef to get rid of zombie
> factors.
>
> purgef<-function(x) lapply(x, function(x) x[drop = TRUE])
>
>
> So, here, before your boxplot
>
> dat$ageclass <- purgef(dat$ageclass)
>
Two points:
* the latest version of R has a built-in droplevels() function
* the problem here is dropping missing *interaction* terms.
I think the OP needs:
transform(dat,agesex=droplevels(interaction(ageclass,sex)))
(or just dat$agesex = with(dat,droplevels(interaction(ageclass,sex)))
boxplot(y~agesex,data=dat)
>>
> On Jan 6, 2011, at 9:09 AM, Howe, Eric (MNR) wrote:
>
>> Good day list members,
>>
>>
>>
>> I was wondering if anyone knows a way to omit specific columns or
>> anova cells from boxplots.
>>
>>
>>
>> E.g. I produce a boxplot as:
>>
>>
>>
>>> boxplot(y ~ ageclass + sex,data=dat)
>>
>>
>>
>> where ageclass has 4 levels (including 1-year-old), and sex has 2
>> levels, but the only males included in the analysis are
>> one-year-olds.
>>
>> The resulting boxplot illustrates differences among age classes of
>> females, and between male and female one-year-olds.
>>
>> However, it has 3 blank columns, corresponding to subadult, young
>> adult, and mature age classes of males.
>>
>> I'd like to exclude those blank columns from the figure.
>>
>>
>>
>> Thanks in advance,
>>
>>
>>
>> Eric
>>
>>
>>
>>
>>
>>
>> [[alternative HTML version deleted]]
>>
>> _______________________________________________ R-sig-ecology
>> mailing list R-sig-ecology at r-project.org
>> https://stat.ethz.ch/mailman/listinfo/r-sig-ecology
>
> _______________________________________________ R-sig-ecology mailing
> list R-sig-ecology at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-ecology
More information about the R-sig-ecology
mailing list