Re: [R] Boxplot of multiple vectors with different lengths
William, THANK YOU! This nailed it. Very much appreciate the support. R On Mon, Dec 12, 2011 at 6:12 PM, William Dunlap wdun...@tibco.com wrote: If you have already made numeric vectors called a, b, and c a - 1:10 b - sqrt(1:200) c - log2(1:500) and a character vector z containing their names z - c(a, b, c) then make a list containing the data with them with dataList - lapply(z, get, envir=environment()) names(dataList) - z and make your boxplots with boxplot(dataList) Then forget about using the variables a, b, and c and use dataList[[a]], dataList[[b]], etc. instead. You may want to use a shorter name than dataList. Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Ryan Utz Sent: Monday, December 12, 2011 3:15 PM To: r-help@r-project.org Subject: Re: [R] Boxplot of multiple vectors with different lengths 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. On Mon, Dec 12, 2011 at 4:09 PM, Vining, Kelly kelly.vin...@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-boun...@r-project.org [mailto: r-help-boun...@r-project.org] On Behalf Of Ryan Utz Sent: Monday, December 12, 2011 1:24 PM To: r-help@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@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. -- 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@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. -- 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@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.
Re: [R] Boxplot of multiple vectors with different lengths
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Trevor Carey- Smith Sent: Monday, December 12, 2011 4:22 PM To: r-help@r-project.org Subject: Re: [R] Boxplot of multiple vectors with different lengths On 12/13/2011 12:14 PM, Ryan Utz wrote: 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?! here is one solution if I understand your requirement: aa - rnorm(20) bb - runif(30) cc - rexp(40) z - c(aa,bb,cc) l - lapply(z,get) boxplot(l) Although as Sarah said, this will fail if you use 'c' as a variable name as the list would then contain the function c() rather than the variable you previously defined. That is why my almost identical suggestion added the argument envir=environment() to the lapply command. It makes get() look in the caller-of-lapply's environment first so it picks up the local c. Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com Regards, Trevor 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. On Mon, Dec 12, 2011 at 4:09 PM, Vining, Kellykelly.vin...@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-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Ryan Utz Sent: Monday, December 12, 2011 1:24 PM To: r-help@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@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. -- Please consider the environment before printing this email. NIWA is the trading name of the National Institute of Water Atmospheric Research Ltd. __ 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. __ 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.
[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@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.
Re: [R] Boxplot of multiple vectors with different lengths
Hi, On Mon, Dec 12, 2011 at 4:24 PM, Ryan Utz utz.r...@gmail.com wrote: 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)) Did you look at z? You've made a list with a single element containing three characters: z [[1]] [1] a b c You need instead: z - list(a, b, c) Also, don't call a variable c - that's a built-in function and using the name elsewhere can cause all kinds of problems (look at your own code line, where you use c as a function and as a variable. although that wasn't a problem here). Sarah 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 -- Sarah Goslee http://www.functionaldiversity.org __ 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.
Re: [R] Boxplot of multiple vectors with different lengths
Ryan, I think you could do what you want by having the vector data written to separate files; then create a file containing the individual file names. In R, read the file containing the list of file names and loop through this reading in the individual vector files. Maybe this is an inelegant, brute force approach, but it has worked for me with essentially the same problem. Tom On Mon, Dec 12, 2011 at 4:24 PM, Ryan Utz utz.r...@gmail.com wrote: 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@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. -- Thomas E Adams National Weather Service Ohio River Forecast Center 1901 South State Route 134 Wilmington, OH 45177 EMAIL: thomas.ad...@noaa.gov VOICE: 937-383-0528 FAX:937-383-0033 [[alternative HTML version deleted]] __ 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.
Re: [R] Boxplot of multiple vectors with different lengths
Sorry -- previous versiuon prematurely sent. Full version is: Yikes! You should never have to do this sort of thing (writing stuff out to files, etc.) What is wanted, I believe, is ?do.call as in do.call(boxplot, z) where z is list(a,b,c) as Sarah described. However, I think you might do even better in terms of controlling options, labels, etc. if you would get the data into standard flat file format (data frame) as Result Source 1a 3 b 2 b 5 c ... etc. (This is easy to do in R and via many packages.) and then use he formula interface in the lattice ?bwplot function for th eplot. Cheers, Bert result On Mon, Dec 12, 2011 at 1:43 PM, Thomas Adams thomas.ad...@noaa.gov wrote: Ryan, I think you could do what you want by having the vector data written to separate files; then create a file containing the individual file names. In R, read the file containing the list of file names and loop through this reading in the individual vector files. Maybe this is an inelegant, brute force approach, but it has worked for me with essentially the same problem. Tom On Mon, Dec 12, 2011 at 4:24 PM, Ryan Utz utz.r...@gmail.com wrote: 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@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. -- Thomas E Adams National Weather Service Ohio River Forecast Center 1901 South State Route 134 Wilmington, OH 45177 EMAIL: thomas.ad...@noaa.gov VOICE: 937-383-0528 FAX: 937-383-0033 [[alternative HTML version deleted]] __ 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. -- Bert Gunter Genentech Nonclinical Biostatistics Internal Contact Info: Phone: 467-7374 Website: http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm -- Bert Gunter Genentech Nonclinical Biostatistics Internal Contact Info: Phone: 467-7374 Website: http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm __ 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.
Re: [R] Boxplot of multiple vectors with different lengths
Bert, I may be mistaken, but I thought Ryan wrote write code that automatically *imports data* from different files (with different lengths-just one variable), so, I was referring to doing something with the data before it gets into R. I understand that one should not need to write out data and then re-read it in some way. As I said, those more experienced with R will probably offer better ideas. Tom On Mon, Dec 12, 2011 at 5:05 PM, Bert Gunter gunter.ber...@gene.com wrote: Sorry -- previous versiuon prematurely sent. Full version is: Yikes! You should never have to do this sort of thing (writing stuff out to files, etc.) What is wanted, I believe, is ?do.call as in do.call(boxplot, z) where z is list(a,b,c) as Sarah described. However, I think you might do even better in terms of controlling options, labels, etc. if you would get the data into standard flat file format (data frame) as Result Source 1a 3 b 2 b 5 c ... etc. (This is easy to do in R and via many packages.) and then use he formula interface in the lattice ?bwplot function for th eplot. Cheers, Bert result On Mon, Dec 12, 2011 at 1:43 PM, Thomas Adams thomas.ad...@noaa.gov wrote: Ryan, I think you could do what you want by having the vector data written to separate files; then create a file containing the individual file names. In R, read the file containing the list of file names and loop through this reading in the individual vector files. Maybe this is an inelegant, brute force approach, but it has worked for me with essentially the same problem. Tom On Mon, Dec 12, 2011 at 4:24 PM, Ryan Utz utz.r...@gmail.com wrote: 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@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. -- Thomas E Adams National Weather Service Ohio River Forecast Center 1901 South State Route 134 Wilmington, OH 45177 EMAIL: thomas.ad...@noaa.gov VOICE: 937-383-0528 FAX:937-383-0033 [[alternative HTML version deleted]] __ 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. -- Bert Gunter Genentech Nonclinical Biostatistics Internal Contact Info: Phone: 467-7374 Website: http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm -- Bert Gunter Genentech Nonclinical Biostatistics Internal Contact Info: Phone: 467-7374 Website: http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm -- Thomas E Adams National Weather Service Ohio River Forecast Center 1901 South State Route 134 Wilmington, OH 45177 EMAIL: thomas.ad...@noaa.gov VOICE: 937-383-0528 FAX:937-383-0033 [[alternative HTML version deleted]] __ 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.
Re: [R] Boxplot of multiple vectors with different lengths
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-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Ryan Utz Sent: Monday, December 12, 2011 1:24 PM To: r-help@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@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. __ 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.
Re: [R] Boxplot of multiple vectors with different lengths
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. On Mon, Dec 12, 2011 at 4:09 PM, Vining, Kelly kelly.vin...@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-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Ryan Utz Sent: Monday, December 12, 2011 1:24 PM To: r-help@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@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. -- 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@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.
Re: [R] Boxplot of multiple vectors with different lengths
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, Kellykelly.vin...@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-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Ryan Utz Sent: Monday, December 12, 2011 1:24 PM To: r-help@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@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. __ 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.
Re: [R] Boxplot of multiple vectors with different lengths
Thomas: I stand corrected. Thank you. -- Bert On Mon, Dec 12, 2011 at 2:21 PM, Thomas Adams thomas.ad...@noaa.gov wrote: Bert, I may be mistaken, but I thought Ryan wrote write code that automatically imports data from different files (with different lengths-just one variable), so, I was referring to doing something with the data before it gets into R. I understand that one should not need to write out data and then re-read it in some way. As I said, those more experienced with R will probably offer better ideas. Tom On Mon, Dec 12, 2011 at 5:05 PM, Bert Gunter gunter.ber...@gene.com wrote: Sorry -- previous versiuon prematurely sent. Full version is: Yikes! You should never have to do this sort of thing (writing stuff out to files, etc.) What is wanted, I believe, is ?do.call as in do.call(boxplot, z) where z is list(a,b,c) as Sarah described. However, I think you might do even better in terms of controlling options, labels, etc. if you would get the data into standard flat file format (data frame) as Result Source 1 a 3 b 2 b 5 c ... etc. (This is easy to do in R and via many packages.) and then use he formula interface in the lattice ?bwplot function for th eplot. Cheers, Bert result On Mon, Dec 12, 2011 at 1:43 PM, Thomas Adams thomas.ad...@noaa.gov wrote: Ryan, I think you could do what you want by having the vector data written to separate files; then create a file containing the individual file names. In R, read the file containing the list of file names and loop through this reading in the individual vector files. Maybe this is an inelegant, brute force approach, but it has worked for me with essentially the same problem. Tom On Mon, Dec 12, 2011 at 4:24 PM, Ryan Utz utz.r...@gmail.com wrote: 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@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. -- Thomas E Adams National Weather Service Ohio River Forecast Center 1901 South State Route 134 Wilmington, OH 45177 EMAIL: thomas.ad...@noaa.gov VOICE: 937-383-0528 FAX: 937-383-0033 [[alternative HTML version deleted]] __ 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. -- Bert Gunter Genentech Nonclinical Biostatistics Internal Contact Info: Phone: 467-7374 Website: http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm -- Bert Gunter Genentech Nonclinical Biostatistics Internal Contact Info: Phone: 467-7374 Website: http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm -- Thomas E Adams National Weather Service Ohio River Forecast Center 1901 South State Route 134 Wilmington, OH 45177 EMAIL:thomas.ad...@noaa.gov VOICE:937-383-0528 FAX: 937-383-0033 -- Bert Gunter Genentech Nonclinical Biostatistics Internal Contact Info: Phone: 467-7374 Website: http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm __ R-help@r-project.org mailing list
Re: [R] Boxplot of multiple vectors with different lengths
If you have already made numeric vectors called a, b, and c a - 1:10 b - sqrt(1:200) c - log2(1:500) and a character vector z containing their names z - c(a, b, c) then make a list containing the data with them with dataList - lapply(z, get, envir=environment()) names(dataList) - z and make your boxplots with boxplot(dataList) Then forget about using the variables a, b, and c and use dataList[[a]], dataList[[b]], etc. instead. You may want to use a shorter name than dataList. Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Ryan Utz Sent: Monday, December 12, 2011 3:15 PM To: r-help@r-project.org Subject: Re: [R] Boxplot of multiple vectors with different lengths 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. On Mon, Dec 12, 2011 at 4:09 PM, Vining, Kelly kelly.vin...@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-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Ryan Utz Sent: Monday, December 12, 2011 1:24 PM To: r-help@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@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. -- 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@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. __ 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.
Re: [R] Boxplot of multiple vectors with different lengths
On 12/13/2011 12:14 PM, Ryan Utz wrote: 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?! here is one solution if I understand your requirement: aa - rnorm(20) bb - runif(30) cc - rexp(40) z - c(aa,bb,cc) l - lapply(z,get) boxplot(l) Although as Sarah said, this will fail if you use 'c' as a variable name as the list would then contain the function c() rather than the variable you previously defined. Regards, Trevor 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. On Mon, Dec 12, 2011 at 4:09 PM, Vining, Kellykelly.vin...@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-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Ryan Utz Sent: Monday, December 12, 2011 1:24 PM To: r-help@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@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. -- Please consider the environment before printing this email. NIWA is the trading name of the National Institute of Water Atmospheric Research Ltd. __ 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.