[R] boxplot

David L Carlson dcarlson at tamu.edu
Thu Mar 21 14:19:00 CET 2013


Your variable loc_type combines information from two variables (loc and
type). Since you are subsetting on loc, why not just plot by type?

boxplot(var1~type, data[data$loc=="nice",])

----------------------------------------------
David L Carlson
Associate Professor of Anthropology
Texas A&M University
College Station, TX 77843-4352

> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
> project.org] On Behalf Of Jim Lemon
> Sent: Thursday, March 21, 2013 4:05 AM
> To: carol white
> Cc: r-help at stat.math.ethz.ch
> Subject: Re: [R] boxplot
> 
> On 03/21/2013 07:40 PM, carol white wrote:
> > Hi,
> > It must be an easy question but how to boxplot a subset of data:
> >
> > data = read.table("my_data.txt", header = T)
> > boxplot(data$var1[data$loc == "nice"]~data$loc_type[data$loc ==
> "nice"])
> > #in this case, i want to display only the boxplot loc == "nice"
> > #doesn't display the boxplot of only loc == "nice". It also displays
> loc == "mice"
> >
> Hi Carol,
> It's them old factors sneakin' up on you. Try this:
> 
> boxplot(data$var1[data$loc == "nice"]~
>   as.character(data$loc_type[data$loc == "nice"]))
> 
> Jim
> 
> ______________________________________________
> R-help at 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.



More information about the R-help mailing list