[R] Boxplot of multiple vectors with different lengths

Peter Ehlers ehlers at ucalgary.ca
Tue Dec 13 00:35:35 CET 2011


On 2011-12-12 15:14, Ryan Utz wrote:
> Thanks for the help, everyone. However, no solution yet...
>
> My vectors names are neatly stored in a character vector of their own. This
> happens based on how they were imported. So, say I have vectors a, b and c,
> all with numeric-only contents. Then I have another vector, say z, that
> looks like this:
>
> z<-c("a","b","c")
>
> Is there really no way to tell boxplot to plot the contents of a, b and c
> while only referencing z?! Why is this so difficult?? Again, this is part
> of an automated process, so the number of incoming data sets, etc. will
> vary, which is why I'm seeking a solution this way.
>

I thought that Bert had given you the answer; try this:

   aa <- runif(15)
   bb <- rnorm(30)
   cc <- rnorm(50,sd=2)
   z <- c(aa,bb,cc)
   g <- rep(LETTERS[1:3],c(length(aa),length(bb),length(cc)))
   boxplot(z ~ g)


Peter Ehlers

>
>
> On Mon, Dec 12, 2011 at 4:09 PM, Vining, Kelly<Kelly.Vining at oregonstate.edu
>> wrote:
>
>> Ryan,
>> Do you necessarily have to use "list"? Have you tried the usecols=TRUE
>> option in boxplot?
>>
>> Cheers,
>> --Kelly V.
>>
>> -----Original Message-----
>> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org]
>> On Behalf Of Ryan Utz
>> Sent: Monday, December 12, 2011 1:24 PM
>> To: r-help at r-project.org
>> Subject: [R] Boxplot of multiple vectors with different lengths
>>
>> Hello,
>>
>> I'm attempting to write a code that automatically imports data from
>> different files (with different lengths-just one variable) and makes tidy
>> box plots for comparison. I can successfully import the data and create a
>> list of the vectors I want to compare. But I cannot, for the life of me,
>> figure out how to generate box plots using the "list" option. Suppose these
>> are my data:
>>
>> a<-c(1,1,1,1,2,3,2,1,2,3)
>> b<-c(2,2,2,3,4,4,4,3,3)
>> c<-c(4,3,3,2,3,4,5,3,3,3,4,4,5,6,3,2)
>>
>> And this is my list of the vectors I'm interested in:
>>
>>   z<-list(c("a","b","c"))
>>
>> Well, this successfully generates the kind of boxplot I want:
>>
>> boxplot(a,b,c)
>>
>> But this does not:
>>
>> boxplot(z)
>>
>> Because I'm trying to write an automatic plot-generator as the amount of
>> data I'm working with will typically vary, I need to write this to handle
>> any number of data vectors.
>>
>> I've tried every imaginable means of tweaking the name of "z", with zero
>> success. And I've scoured the help pages for about 45 minutes (just to
>> preempt any "read the help" responses). Please help!
>>
>> Thanks,
>> Ryan
>>
>> --
>>
>> Ryan Utz, Ph.D.
>> Aquatic Ecologist/STREON Scientist
>> National Ecological Observatory Network
>>
>> Home/Cell: (724) 272-7769
>> Work: (720) 836-2488
>>
>>          [[alternative HTML version deleted]]
>>
>> ______________________________________________
>> 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