[R] Boxplots using percentiles?

Jacob W. Bowers jbowers at csm.berkeley.edu
Mon Nov 26 02:05:19 CET 2001


Hi.

I wrote a little replacement for boxplot.stats [making as few changes to
boxplot.stats as possible], and then edited boxplot.default to call
"myboxplot.stats" instead of "boxplot.stats": 

#This function replaces boxplot.stats --- it uses the middle 50% and
#middle 90% instead of middle 50%(IQR) and 1.5*IQR.
myboxplot.stats <-  function (x, coef = NULL, do.conf = TRUE, do.out =
TRUE) 
{
  nna <- !is.na(x)
  n <- sum(nna)
  stats <- quantile(x, c(.05,.25,.5,.75,.95), na.rm = TRUE)
  iqr <- diff(stats[c(2, 4)])
  out <- x < stats[1] | x > stats[5]
  conf <- if (do.conf) 
    stats[3] + c(-1.58, 1.58) * diff(stats[c(2, 4)])/sqrt(n)
  list(stats = stats, n = n, conf = conf, out = x[out & nna])
}

So, when I call boxplot(), the whiskers show the middle 90% of the
distribution.

I hope this helps.
Jake

--
Jake Bowers
Dept of Political Science
UC-Berkeley


On Sun, 25 Nov 2001, Robert Gentleman wrote:

> On Mon, Nov 26, 2001 at 11:25:36AM +1300, Nick Davis wrote:
> > The standard R boxplot appears to use quartiles to determine the height of
> > the rectangles and a range parameter - RNG - (default=1.5 I think) that
> > determines the length of the whiskers as <= RNG x Interquartile Range.  Is
> > it possible to instead define the range as extending to the 95th percentile?
> > If so, how would this be done?  
> 
>  You need to create the right kind of thing to call bxp -- which has
>  some documentation but basically it is the z component that you need
>  to construct.
> 
>  You can call boxplot with plot=FALSE to get it to do most of the work
>  and then just fiddle with the parts you want to change
> 
> >  
> > nb, I'm plotting multiple boxplots on a single chart so a function that
> > applies to multiple series would be useful.
> >  
> > Thanks,
> >  
> > Nick
> 
> -- 
> +---------------------------------------------------------------------------+
> | Robert Gentleman                 phone : (617) 632-5250                   |
> | Associate Professor              fax:   (617)  632-2444                   |
> | Department of Biostatistics      office: M1B28
> | Harvard School of Public Health  email: rgentlem at jimmy.dfci.harvard.edu   |
> +---------------------------------------------------------------------------+
> -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
> r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
> Send "info", "help", or "[un]subscribe"
> (in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
> _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
> 

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list