How to make a boxplot with exclusion of certain groups

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

How to make a boxplot with exclusion of certain groups

Josef.Kardos
This seems like a simple thing, but I have been stuck for some time.  My
data has 2 columns.  Column 1 is the value, and column 2 is the Site where
data was collected.  Column 2 contains 7 different Sites (i.e. groups).  I
am only interested in showing 3 groups on a single boxplot.

I have tried various methods of subsetting the data, in order to only have
the 3 groups in my subset.  However even after doing this, all 7 groups
carry forward, so that when I make a boxplot of my subsetted data, all 7
groups still appear in the x-axis labels; all 7 groups also appear in the
boxplot summary (i.e. the values returned with boxplot (…plot=FALSE)  ) .
Even if I delete the unwanted groups from the ‘levels’ of Column 2, they
still appear on the plot, and in the boxplot summary statistics.

There are various tricks I can do with the boxplot summary statistics to
correct for this, but they get complicated when I want to change the
algorithm for calculating outliers and their corresponding groups. Rather
than do all these tricks, it seems much simpler to fully exclude the
unwanted groups from the beginning.  But this doesn’t appear to work

Any ideas?

        [[alternative HTML version deleted]]


______________________________________________
[hidden email] 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 | Threaded
Open this post in threaded view
|

Re: How to make a boxplot with exclusion of certain groups

Chuck Cleland
On 4/19/2010 12:21 PM, [hidden email] wrote:

> This seems like a simple thing, but I have been stuck for some time.  My
> data has 2 columns.  Column 1 is the value, and column 2 is the Site where
> data was collected.  Column 2 contains 7 different Sites (i.e. groups).  I
> am only interested in showing 3 groups on a single boxplot.
>
> I have tried various methods of subsetting the data, in order to only have
> the 3 groups in my subset.  However even after doing this, all 7 groups
> carry forward, so that when I make a boxplot of my subsetted data, all 7
> groups still appear in the x-axis labels; all 7 groups also appear in the
> boxplot summary (i.e. the values returned with boxplot (…plot=FALSE)  ) .
> Even if I delete the unwanted groups from the ‘levels’ of Column 2, they
> still appear on the plot, and in the boxplot summary statistics.
>
> There are various tricks I can do with the boxplot summary statistics to
> correct for this, but they get complicated when I want to change the
> algorithm for calculating outliers and their corresponding groups. Rather
> than do all these tricks, it seems much simpler to fully exclude the
> unwanted groups from the beginning.  But this doesn’t appear to work
>
> Any ideas?

library(gdata) # for drop.levels()

DF <- data.frame(site = rep(LETTERS[1:7], each=20), y = runif(7*20))

boxplot(y ~ drop.levels(site), data=subset(DF, site %in% c('A','D','F'),
drop=TRUE))

> [[alternative HTML version deleted]]
>
>
>
> ------------------------------------------------------------------------
>
> ______________________________________________
> [hidden email] 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.

--
Chuck Cleland, Ph.D.
NDRI, Inc. (www.ndri.org)
71 West 23rd Street, 8th floor
New York, NY 10010
tel: (212) 845-4495 (Tu, Th)
tel: (732) 512-0171 (M, W, F)
fax: (917) 438-0894

______________________________________________
[hidden email] 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.