[R] displaying sample size in boxplots

Patrick Drechsler patrick.drechsler at gmx.net
Wed Sep 29 15:52:03 CEST 2004

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!


Snoopy (on being house-trained with a rolled-up newspaper): 
It does tend however to give one a rather distorted view of the press!

More information about the R-help mailing list