Re: [R] displaying sample size in boxplots
Gabor Grothendieck wrote on 13 Oct 2004 07:16:07 MET: > Warnes, Gregory R pfizer.com> writes: > : > Since I'm still new to R: can somebody give me a pointer to the > : > docs where to find instructions on a package (not a function)? I > : > can find the man pages to specific functions with ? > : > (something similar to `texdoc ' in tetex)? > : > : library(help=) > : > : you can also get the PDF package documentation available on cran, e.g. > : http://cran.r-project.org/doc/packages/gregmisc.pdf [snip] > Also some packages, though not many, have vignettes which are > documents that describe the package as a whole as opposed to > single functions. Just issue the command: > >vignette() [snip] Greg and Gabor: Thank you for the pointers! Cheers Patrick -- "I really should talk to him. He's had a near-death experience!" "We all have. It's called living." Terry Pratchett, Hogfather __ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] displaying sample size in boxplots
Warnes, Gregory R pfizer.com> writes: : : > -Original Message- : > From: r-help-bounces stat.math.ethz.ch : > [mailto:r-help-bounces stat.math.ethz.ch]On Behalf Of Patrick : > Drechsler : > : > Gregory R. Warnes wrote on 01 Oct 2004 14:52:05 MET: : > : > [...] : > : > > Also note that boxplot.n in the gplots library (part of the : > > gregmisc bundle) automatically adds the number of observations. : > : > Thanks Greg! Nice to see that you've written some code just for : > this purpose. I will of course also take a closer look at the : > other functions that are bundled in `gregmisc'. : > : : :^) : : > Since I'm still new to R: can somebody give me a pointer to the : > docs where to find instructions on a package (not a function)? I : > can find the man pages to specific functions with ? : > (something similar to `texdoc ' in tetex)? : : library(help=) : : you can also get the PDF package documentation available on cran, e.g. : http://cran.r-project.org/doc/packages/gregmisc.pdf : : -Greg Also some packages, though not many, have vignettes which are documents that describe the package as a whole as opposed to single functions. Just issue the command: vignette() to get a list. Assuming you have the package strucchange installed, the above command will have let you know that strucchange has a vignette called strucchange-intro which you can view like this: vignette("strucchange-intro") Check out the R News article on vignettes in R News 3/2 for more info. In addition, its always a good idea to check if there is an R News article on the package. In the case of strucchange, a google search for rnews strucchange would have found a reference telling you what issue its in. R News is found via the Newsletter link on the www.r-project.org home page. __ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
RE: [R] displaying sample size in boxplots
> -Original Message- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] Behalf Of Patrick > Drechsler > > Gregory R. Warnes wrote on 01 Oct 2004 14:52:05 MET: > > [...] > > > Also note that boxplot.n in the gplots library (part of the > > gregmisc bundle) automatically adds the number of observations. > > Thanks Greg! Nice to see that you've written some code just for > this purpose. I will of course also take a closer look at the > other functions that are bundled in `gregmisc'. > :^) > Since I'm still new to R: can somebody give me a pointer to the > docs where to find instructions on a package (not a function)? I > can find the man pages to specific functions with ? > (something similar to `texdoc ' in tetex)? library(help=) you can also get the PDF package documentation available on cran, e.g. http://cran.r-project.org/doc/packages/gregmisc.pdf -Greg > > TIA, > > Patrick > -- > Look Ma, this man can twist his fingers as if they were made of > rubber, isn't that amazing? -- Not really, he's been using Emacs > for years...! > > __ > [EMAIL PROTECTED] mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html > LEGAL NOTICE\ Unless expressly stated otherwise, this messag...{{dropped}} __ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] displaying sample size in boxplots
Gregory R. Warnes wrote on 01 Oct 2004 14:52:05 MET: [...] >> > Here are the current proposals [for cut & paste]: >> > >> > library(ISwR) >> > data(energy) >> > attach(energy) >> > >> > ## 1 >> > boxplot(expend~stature) >> > sample.size <- tapply(expend, stature, length) >> > ss.ch <- paste("N=", sample.size, sep="") >> > mtext(ss.ch, at=1:length(unique(stature)), line=2, side=1) >> > >> > ## 2 (Roger) >> > boxplot(expend~stature, width=sample.size/length(expend), >> > names=paste(levels(stature), ", N=", sample.size, sep="")) >> > >> > ## 3 (Roger + Martin): >> > boxplot(expend ~ stature, varwidth= TRUE, >> > names=paste(levels(stature), ", N=", sample.size, sep="")) [...] > Also note that boxplot.n in the gplots library (part of the > gregmisc bundle) automatically adds the number of observations. Thanks Greg! Nice to see that you've written some code just for this purpose. I will of course also take a closer look at the other functions that are bundled in `gregmisc'. Since I'm still new to R: can somebody give me a pointer to the docs where to find instructions on a package (not a function)? I can find the man pages to specific functions with ? (something similar to `texdoc ' in tetex)? TIA, Patrick -- Look Ma, this man can twist his fingers as if they were made of rubber, isn't that amazing? -- Not really, he's been using Emacs for years...! __ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
RE: [R] displaying sample size in boxplots
Also note that boxplot.n in the gplots library (part of the gregmisc bundle) automatically adds the number of observations. -Greg > -Original Message- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] Behalf Of Patrick > Drechsler > Sent: Wednesday, September 29, 2004 1:47 PM > To: [EMAIL PROTECTED] > Subject: Re: [R] displaying sample size in boxplots > > > > Martin Maechler wrote on 29 Sep 2004 17:11:13 MET: > > >>>>>> "Roger" == Roger Bivand <[EMAIL PROTECTED]> > >>>>>> on Wed, 29 Sep 2004 15:09:17 +0200 (CEST) writes: > [snip] > > > Roger> Perhaps use the names= argument (width can help too): > > ^^ > > Indeed! > > And that's why -- "in the good ol' times" when the box plot > was invented > > and enhanced, the inventors thought about it. > > For that reason there's the 'varwidth = TRUE/FALSE' argument > > in boxplot() > > > > Note from help(boxplot) however that the inventors thought > > it wiser to make the width proportional to the SQRT of the > > sample size rather than the sample.size itself, i.e., > > 'varwidth = TRUE' and your proposal are not equivalent. > > > > >> boxplot(expend~stature, width=sample.size/length(expend), > > >> + names=paste(levels(stature), ", N=", > sample.size, sep="")) > > > > Here are the current proposals [for cut & paste]: > > > > library(ISwR) > > data(energy) > > attach(energy) > > > > ## 1 > > boxplot(expend~stature) > > sample.size <- tapply(expend, stature, length) > > ss.ch <- paste("N=", sample.size, sep="") > > mtext(ss.ch, at=1:length(unique(stature)), line=2, side=1) > > > > ## 2 (Roger) > > boxplot(expend~stature, width=sample.size/length(expend), > > names=paste(levels(stature), ", N=", sample.size, sep="")) > > > > ## 3 (Roger + Martin): > > boxplot(expend ~ stature, varwidth= TRUE, > > names=paste(levels(stature), ", N=", sample.size, sep="")) > > Thanks for the explanation and the nice summary Martin! I can see > the point you're making about varwidth. I've read that part in > the documentation before but I have to admit that up to now I > didn't see the purpose of this parameter. Although there are > situations were I prefer to see the number in print somewhere on > the plot which I can now easily accomplish with `names'. > > Also thanks to Stephano for the pointer to the r-newsletter > article and to Don for showing me how one implements user > defined functions! > > Cheers > > Patrick > -- > For animals, the entire universe has been neatly divided into things > to (a) mate with, (b) eat, (c) run away from, and (d) rocks. > -- (Terry Pratchett, Equal Rites) > > __ > [EMAIL PROTECTED] mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html > LEGAL NOTICE\ Unless expressly stated otherwise, this messag...{{dropped}} __ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] displaying sample size in boxplots
Martin Maechler wrote on 29 Sep 2004 17:11:13 MET: >> "Roger" == Roger Bivand <[EMAIL PROTECTED]> >> on Wed, 29 Sep 2004 15:09:17 +0200 (CEST) writes: [snip] > Roger> Perhaps use the names= argument (width can help too): > ^^ > Indeed! > And that's why -- "in the good ol' times" when the box plot was invented > and enhanced, the inventors thought about it. > For that reason there's the 'varwidth = TRUE/FALSE' argument > in boxplot() > > Note from help(boxplot) however that the inventors thought > it wiser to make the width proportional to the SQRT of the > sample size rather than the sample.size itself, i.e., > 'varwidth = TRUE' and your proposal are not equivalent. > > >> boxplot(expend~stature, width=sample.size/length(expend), > >> + names=paste(levels(stature), ", N=", sample.size, sep="")) > > Here are the current proposals [for cut & paste]: > > library(ISwR) > data(energy) > attach(energy) > > ## 1 > boxplot(expend~stature) > sample.size <- tapply(expend, stature, length) > ss.ch <- paste("N=", sample.size, sep="") > mtext(ss.ch, at=1:length(unique(stature)), line=2, side=1) > > ## 2 (Roger) > boxplot(expend~stature, width=sample.size/length(expend), > names=paste(levels(stature), ", N=", sample.size, sep="")) > > ## 3 (Roger + Martin): > boxplot(expend ~ stature, varwidth= TRUE, > names=paste(levels(stature), ", N=", sample.size, sep="")) Thanks for the explanation and the nice summary Martin! I can see the point you're making about varwidth. I've read that part in the documentation before but I have to admit that up to now I didn't see the purpose of this parameter. Although there are situations were I prefer to see the number in print somewhere on the plot which I can now easily accomplish with `names'. Also thanks to Stephano for the pointer to the r-newsletter article and to Don for showing me how one implements user defined functions! Cheers Patrick -- For animals, the entire universe has been neatly divided into things to (a) mate with, (b) eat, (c) run away from, and (d) rocks. -- (Terry Pratchett, Equal Rites) __ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] displaying sample size in boxplots
> "Roger" == Roger Bivand <[EMAIL PROTECTED]> > on Wed, 29 Sep 2004 15:09:17 +0200 (CEST) writes: Roger> On Wed, 29 Sep 2004, Patrick Drechsler wrote: >> Hi, >> >> I was wondering if there is a ready made function or parameter >> for indicating the sample size in boxplots? >> >> Here's what I came up with so far: >> >> library(ISwR) >> data(energy) >> attach(energy) >> boxplot(expend~stature) >> sample.size <- tapply(expend, stature, length) >> sample.size <- paste("N=", sample.size, sep="") >> mtext(sample.size, at=1:length(unique(stature)), line=2, side=1) >> Roger> Perhaps use the names= argument (width can help too): ^^ Indeed! And that's why -- "in the good ol' times" when the box plot was invented and enhanced, the inventors thought about it. For that reason there's the 'varwidth = TRUE/FALSE' argument in boxplot() Note from help(boxplot) however that the inventors thought it wiser to make the width proportional to the SQRT of the sample size rather than the sample.size itself, i.e., 'varwidth = TRUE' and your proposal are not equivalent. >> boxplot(expend~stature, width=sample.size/length(expend), >> + names=paste(levels(stature), ", N=", sample.size, sep="")) Here are the current proposals [for cut & paste]: library(ISwR) data(energy) attach(energy) ## 1 boxplot(expend~stature) sample.size <- tapply(expend, stature, length) ss.ch <- paste("N=", sample.size, sep="") mtext(ss.ch, at=1:length(unique(stature)), line=2, side=1) ## 2 (Roger) boxplot(expend~stature, width=sample.size/length(expend), names=paste(levels(stature), ", N=", sample.size, sep="")) ## 3 (Roger + Martin): boxplot(expend ~ stature, varwidth= TRUE, names=paste(levels(stature), ", N=", sample.size, sep="")) __ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] displaying sample size in boxplots
Hi Roger, Roger Bivand wrote on 29 Sep 2004 14:09:17 MET: > On Wed, 29 Sep 2004, Patrick Drechsler wrote: > >> I was wondering if there is a ready made function or parameter >> for indicating the sample size in boxplots? >> >> Here's what I came up with so far: >> >> library(ISwR) >> data(energy) >> attach(energy) >> boxplot(expend~stature) >> sample.size <- tapply(expend, stature, length) >> sample.size <- paste("N=", sample.size, sep="") >> mtext(sample.size, at=1:length(unique(stature)), line=2, side=1) >> > > Perhaps use the names= argument (width can help too): > >> boxplot(expend~stature, width=sample.size/length(expend), > + names=paste(levels(stature), ", N=", sample.size, sep="")) Also many thanks to you for the quick help! Your solution (as well as Marc's) work like a charm! Cheers Patrick -- Snoopy (on being house-trained with a rolled-up newspaper): It does tend however to give one a rather distorted view of the press! __ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] displaying sample size in boxplots
Here is how I do it: function (x, ...) { bx <- boxplot(x, plot = F, ...) bx$names <- paste(bx$names, "\nn = ", bx$n, sep = "") tmp <- bxp(bx, tcl = 0, xaxt = "n") axis(1, at = tmp, labels = bx$names, tick = FALSE) invisible(c(bx, list(x = tmp))) } -Don At 2:46 PM +0200 9/29/04, Patrick Drechsler wrote: Hi, I was wondering if there is a ready made function or parameter for indicating the sample size in boxplots? Here's what I came up with so far: library(ISwR) data(energy) attach(energy) boxplot(expend~stature) sample.size <- tapply(expend, stature, length) sample.size <- paste("N=", sample.size, sep="") mtext(sample.size, at=1:length(unique(stature)), line=2, side=1) TIA, Patrick -- "What happens if a big asteroid hits Earth ? Judging from realistic simulations involving a sledge hammer and a common laboratory frog, we can assume it will be pretty bad." -- Dave Barry __ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html -- -- Don MacQueen Environmental Protection Department Lawrence Livermore National Laboratory Livermore, CA, USA __ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] displaying sample size in boxplots
Hi Marc, Marc Schwartz wrote on 29 Sep 2004 14:08:19 MET: > On Wed, 2004-09-29 at 07:46, Patrick Drechsler wrote: >> I was wondering if there is a ready made function or parameter >> for indicating the sample size in boxplots? [...] > Note that boxplot() returns values, which includes a variety of > summary information on each group within your data. See the > "Value" section of ?boxplot and ?boxplot.stats for more > information. > > Thus, you can do something like (using the first example in > ?boxplot): > > data(InsectSprays) > > # Save the returned values from boxplot() in "S" > S <- boxplot(count ~ spray, data = InsectSprays, col = "lightgray") > > # S$n is the sample size for each group > # S$names contains the group names > mtext(side = 1, text = S$n, at = 1:length(S$names), line = 2) Thank you very much--just what I was looking for! Patrick -- "Ludwig Boltzmann, who spent much of his life studying statistical mechanics, died in 1906, by his own hand. Paul Ehrenfest, carrying on the work, died similarly in 1933. Now it is our turn to study statistical mechanics. Perhaps it will be wise to approach the subject cautiously." from "States of Matter" by David Goodstein __ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] displaying sample size in boxplots
On Wed, Sep 29, 2004 at 08:08:19AM -0500, Marc Schwartz wrote: > On Wed, 2004-09-29 at 07:46, Patrick Drechsler wrote: > > Hi, > > > > I was wondering if there is a ready made function or parameter > > for indicating the sample size in boxplots? > > > > Here's what I came up with so far: > > > > library(ISwR) > > data(energy) > > attach(energy) > > boxplot(expend~stature) > > sample.size <- tapply(expend, stature, length) > > sample.size <- paste("N=", sample.size, sep="") > > mtext(sample.size, at=1:length(unique(stature)), line=2, side=1) > In vol 3/2 October 2003 of R news there's an extended version of boxplot, with median and mean ticks, etc. and also sample dimension. HIH, Stefano > > __ > [EMAIL PROTECTED] mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] displaying sample size in boxplots
On Wed, 29 Sep 2004, Patrick Drechsler wrote: > Hi, > > I was wondering if there is a ready made function or parameter > for indicating the sample size in boxplots? > > Here's what I came up with so far: > > library(ISwR) > data(energy) > attach(energy) > boxplot(expend~stature) > sample.size <- tapply(expend, stature, length) > sample.size <- paste("N=", sample.size, sep="") > mtext(sample.size, at=1:length(unique(stature)), line=2, side=1) > Perhaps use the names= argument (width can help too): > boxplot(expend~stature, width=sample.size/length(expend), + names=paste(levels(stature), ", N=", sample.size, sep="")) > TIA, > > Patrick > -- Roger Bivand Economic Geography Section, Department of Economics, Norwegian School of Economics and Business Administration, Breiviksveien 40, N-5045 Bergen, Norway. voice: +47 55 95 93 55; fax +47 55 95 93 93 e-mail: [EMAIL PROTECTED] __ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] displaying sample size in boxplots
On Wed, 2004-09-29 at 07:46, Patrick Drechsler wrote: > Hi, > > I was wondering if there is a ready made function or parameter > for indicating the sample size in boxplots? > > Here's what I came up with so far: > > library(ISwR) > data(energy) > attach(energy) > boxplot(expend~stature) > sample.size <- tapply(expend, stature, length) > sample.size <- paste("N=", sample.size, sep="") > mtext(sample.size, at=1:length(unique(stature)), line=2, side=1) Note that boxplot() returns values, which includes a variety of summary information on each group within your data. See the "Value" section of ?boxplot and ?boxplot.stats for more information. Thus, you can do something like (using the first example in ?boxplot): data(InsectSprays) # Save the returned values from boxplot() in "S" S <- boxplot(count ~ spray, data = InsectSprays, col = "lightgray") # S$n is the sample size for each group # S$names contains the group names mtext(side = 1, text = S$n, at = 1:length(S$names), line = 2) HTH, Marc Schwartz __ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html