[R] Box plot with 5th and 95th percentiles instead of 1.5 * IQR: problems implementing an existing solution...

Olaf goelaf at gmx.net
Wed Jul 17 11:14:10 CEST 2013

```Hello,
you may just first change the boxplot.stats directly:

boxplot.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])
}

then use it plotting your data.
And after that change them back :

boxplot.stats <- function (x, coef = 1.5, do.conf = TRUE, do.out = TRUE)
{
if (coef < 0)
stop("'coef' must not be negative")
nna <- !is.na(x)
n <- sum(nna)
stats <- stats::fivenum(x, na.rm = TRUE)
iqr <- diff(stats[c(2, 4)])
if (coef == 0)
do.out <- FALSE
else {
out <- if (!is.na(iqr)) {
x < (stats[2L] - coef * iqr) | x > (stats[4L] + coef *
iqr)
}
else !is.finite(x)
if (any(out[nna], na.rm = TRUE))
stats[c(1, 5)] <- range(x[!out], na.rm = TRUE)
}
conf <- if (do.conf)
stats[3L] + c(-1.58, 1.58) * iqr/sqrt(n)
list(stats = stats, n = n, conf = conf, out = if (do.out) x[out &
nna] else
numeric())
}

it works fine for me.

--
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-tp3456123p4671739.html
Sent from the R help mailing list archive at Nabble.com.

```