[R] displaying sample size in boxplots

Roger Bivand
2004-09-29T13:09:17Z

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