[R] displaying sample size in boxplots

Don MacQueen macq at llnl.gov
Wed Sep 29 15:49:16 CEST 2004


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
>
>______________________________________________
>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


-- 
--------------------------------------
Don MacQueen
Environmental Protection Department
Lawrence Livermore National Laboratory
Livermore, CA, USA




More information about the R-help mailing list