[R] Odp: Modifying whiskers in boxplots?

Petr PIKAL petr.pikal at precheza.cz
Mon Jan 30 11:33:53 CET 2012


Hi

> 
> Hello,
> 
> I know this has been covered on here before, but as a complete novice, I
> need a little more guidance.  I would like to produce boxplots with the
> whiskers extending to the 10 and 90th percentiles.  I found this code:
> 
> myboxplot.stats <-  function (x, coef = NULL, do.conf = TRUE, do.out =
> TRUE)
> {
>   nna <- !is.na(x)
>   n <- sum(nna)
>   stats <- quantile(x, c(.1,.25,.5,.75,.9), 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])
> }
> 
> posted by Mr. Jim Bowers, and additional posts discussing how to make
> it work.  The issue I am having is that all the posts say to edit
> boxplot.default, but I have no idea how to actually do that.  I've
> tried fix(bowplot.default)

I do not see any need for modifying boxplot.default. You could change 
$stats part of list produced from boxplot call

set.seed(111)
x<-rnorm(100)
bb<-boxplot(x, plot=F)

quantile(x,c(.1,.9))
      10%       90% 
-1.315051  1.400721 

bb$stats
           [,1]
[1,] -2.3023457
[2,] -0.7581696
[3,]  0.1315965
[4,]  0.6211842
[5,]  2.4856616

bb$stats[c(1,5),]<-quantile(x,c(.1,.9))
> bb$stats
           [,1]
[1,] -1.3150509
[2,] -0.7581696
[3,]  0.1315965
[4,]  0.6211842
[5,]  1.4007212

> bxp(bb, add=T, col=2)

Regards
Petr


> 
> and fixInNamespace(...), but what do I actually change?  I tried
> including an argument "stats=myboxplot.stats" but that did not change
> anything.  Once it is changed, can I just use the same "boxplot(...)"
> code as normal or
> 
> do I need to use myboxplot?  I know this should be simple, but it is
> generating a lot of frustration.  Any help would be greatly
> appreciated.
> 
> Thanks, James
> 
>    [[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list