[R] displaying sample size in boxplots

Roger Bivand Roger.Bivand at nhh.no
Wed Sep 29 15:09:17 CEST 2004


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: Roger.Bivand at nhh.no




More information about the R-help mailing list