[R] Box plot with 5th and 95th percentiles instead of 1.5 * IQR: problems implementing an existing solution...
f.harrell at vanderbilt.edu
Sun Apr 17 23:56:19 CEST 2011
This implements extended box plots that can show a variety of quantiles.
Paul Raftery wrote:
> Hi all,
> I'm just getting started with R and I would appreciate some help. I'm
> trouble creating a boxplot with whiskers at the 95th and 5th percentiles
> instead of at 1.5 * IQR. I have read the relevant documentation, and
> existing mails on this topic. I found a small modification that should
> : https://stat.ethz.ch/pipermail/r-help/2001-November/016817.html and
> to implement it.
> Basically, it says to replace boxplot.stats with:
> myboxplot.stats <- function (x, coef = NULL, do.conf = TRUE, do.out =
> 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 | x > stats
> conf <- if (do.conf)
> stats + c(-1.58, 1.58) * diff(stats[c(2, 4)])/sqrt(n)
> list(stats = stats, n = n, conf = conf, out = x[out & nna])
> I entered the new function, and used fix(boxplot.default) to modify
> boxplot.default so that it references myboxplot.stats instead of the
> original boxplot.stats function.
> If I now type boxplot.default, I can see that the code has been modified
> expected. However, I get the exact same result as before when I create a
> boxplot - it shows the whiskers at 1.5 * IQR. You can test this out by
> creating a boxplot from the iris dataset supplied with R using
> boxplot(iris$Sepal.Length ~ iris$Species). You see that the boxplot is the
> same before and after the fix. Does anybody know why this occurs, and how
> can get around this issue?
> Contact Details
> Paul Raftery, BEng(Hons) (Mech), Fulbright Fellow, PhD
> Postdoctoral Research Engineer
> Informatics Research Unit for Sustainable Engineering (IRUSE)
> Department of Civil Engineering,
> National University of Ireland, Galway,
> University Road,
> Landline: +353 91 49 3086
> Mobile: +353 85 124 7947
> Skype: praftery
> [[alternative HTML version deleted]]
> R-help at r-project.org mailing list
> PLEASE do read the posting guide
> and provide commented, minimal, self-contained, reproducible code.
Department of Biostatistics, Vanderbilt University
View this message in context: http://r.789695.n4.nabble.com/Box-plot-with-5th-and-95th-percentiles-instead-of-1-5-IQR-problems-implementing-an-existing-solution-tp3456123p3456187.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help