[R] displaying sample size in boxplots

Warnes, Gregory R gregory_r_warnes at groton.pfizer.com
Fri Oct 1 15:52:05 CEST 2004


Also note that boxplot.n in the gplots library (part of the gregmisc bundle)
automatically adds the number of observations.

-Greg


> -----Original Message-----
> From: r-help-bounces at stat.math.ethz.ch
> [mailto:r-help-bounces at stat.math.ethz.ch]On Behalf Of Patrick 
> Drechsler
> Sent: Wednesday, September 29, 2004 1:47 PM
> To: r-help at stat.math.ethz.ch
> Subject: Re: [R] displaying sample size in boxplots
> 
> 
> 
> Martin Maechler wrote on 29 Sep 2004 17:11:13 MET:
> 
> >>>>>> "Roger" == Roger Bivand <Roger.Bivand at nhh.no>
> >>>>>>     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)
> 
> ______________________________________________
> R-help at stat.math.ethz.ch 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}}




More information about the R-help mailing list