Skip to content

boxplots

3 messages · Martin Olofsson, Sarah Goslee, Joshua Wiley

#
Hi!

My name is Martin and I have a problem concerning the boxplot function 
in R. I want my boxes to be limited by the 1st and 3rd quartile and NOT 
the 'hinges' values that are the default setting in R.
Do anyone knows if there is any command that I could do to change this 
default setting?

Sincerely

Martin Olofsson
#
Martin,

I don't know of an easy way to make that change, but do note:

     The two ?hinges? are versions of the first and third quartile,
     i.e., close to ?quantile(x, c(1,3)/4)?.  The hinges equal the
     quartiles for odd n (where ?n <- length(x)?) and differ for even
     n.  Whereas the quartiles only equal observations for ?n %% 4 ==
     1? (n = 1 mod 4), the hinges do so _additionally_ for ?n %% 4 ==
     2? (n = 2 mod 4), and are in the middle of two observations
     otherwise.

(from the help for boxplot.stats), so it may not make any substantial
difference. You could always call boxplot.stats() on your data and see
whether the values used are close enough to the values you want to
make it not worth fiddling.

If they aren't, you'll need to look into boxplot.stats() and bxp(), I think.
You might also look into the boxplot functions in contributed packages.

Sarah

On Fri, Jul 29, 2011 at 7:39 AM, Martin Olofsson
<martin.olofsson at zoologi.su.se> wrote:

  
    
  
#
Hi Martin,

As Sarah said, I do not know of any way to "change the default", but
you can certainly do it manually each time.  Here is an example:

## generate some data
set.seed(10)
x <- rnorm(101)
## store boxplot results
s <- boxplot(x, plot = FALSE)
## look at them
s
## replace the stats with lower and upper quartile
s$stats[c(2, 4), 1] <- quantile(x, c(.25, .75), TRUE, type = 7)
## plot updated boxplot
bxp(s)

That said, you will still have to pick what algorithm you want for
your quartiles.  This demonstrates the nine algorithms:

t(sapply(1:9, function(i) quantile(x, c(.25, .75), TRUE, type = i)))

You can find their specific details in the article:

Hyndman, R. J., & Fan, Y. (1996). Sample Quantiles in Statistical
Packages. The American Statistician, 50(4), 361 - 365.

Hope this helps,

Josh

On Fri, Jul 29, 2011 at 4:39 AM, Martin Olofsson
<martin.olofsson at zoologi.su.se> wrote: