Skip to content

Boxplot has only one whisker

6 messages · Tom, Ivan Calandra, David Winsemius

Tom
#
Hello!

I am using box plot and one of my boxes has only one whisker. How can I
change this?

Code:
bp<-c(2.7, 3.1, 3.5, 8.95)

Methode1 <- quantile(bp,type = 7)
Methode2 <- quantile(bp,type = 2)
d<-data.frame(Methode1,Methode2)
boxplot(d,ylab = "Beispiel 1",range = 1.5)
http://r.789695.n4.nabble.com/file/n2993262/boxplot_with_one_whisker.png 

Thanks!
Tom
#
Try with more data points?!
You have only five points, the last one being considered as outlier.
Note that boxplot() requires a numeric vector for specifying data from 
which the boxplots are to be produced!

HTH
Ivan

Le 10/13/2010 09:50, tom a ?crit :

  
    
Tom
#
Ivan Calandra wrote:
But why is only one of the boxplots missing his whisker? I use the same data
for both boxplots.
thx,
tom
#
Well, you don't use the same data for both.
Type 2 and 7 give different values for the 25 and 75%, which correspond 
more or less to the box hinges.
If you take a look at how the whiskers are defined (look at ?boxplot.stats):
"|coef| this determines how far the plot ?whiskers? extend out from the 
box. If |coef| is positive, the whiskers extend to the most extreme data 
point which is no more than |coef| times the length of the box away from 
the box."
In your example, the box for "method1" is short; the 100% point is then 
further that 1.5*length of the box (IQR), which is then considered as 
outlier. Note that the default for coef is 1.5 (hence the 1.5*IQR). On 
the other hand, for method 2, the box is longer; the largest point is 
therefore within 1.5*IQR and plotted with the upper whisker.
Understand what I mean?
See that post too, they might have better explanations:
http://finzi.psych.upenn.edu/Rhelp10/2010-May/238597.html

But don't forget my second comment: you boxplot() summary data. From my 
understanding, you should not do that. Boxplot() returns the statistics 
itself (look at the value section from ?boxplot). Try:
bx <- boxplot(d,ylab = "Beispiel 1",range = 1.5)
bx$stats
[,1] [,2]
[1,] 2.7000 2.700
[2,] 3.0000 2.900
[3,] 3.3000 3.300
[4,] 4.8625 6.225
[5,] 4.8625 8.950

You can see that boxplot() recomputed the summary stats from the summary 
stats you gave as input, and plotted them!
You should provide raw data to boxplot(), not summary stats.
If you want to input summary stats, there was a post some time ago on that:
http://finzi.psych.upenn.edu/Rhelp10/2010-September/251674.html

HTH,
Ivan

Le 10/13/2010 10:33, tom a ?crit :

  
    
#
On Oct 13, 2010, at 5:06 AM, Ivan Calandra wrote:

            
Agreed,  boxplot is doing the summarization, but it then hands the  
summaries on to bxp() to do the plotting. So if the OP wants to add  
back in a whisker or a dot or to use summaries from another source,  
then he should first look at the Value section of the boxplot help  
page for the correct list structure, and then send that list to bxp().  
The bxp help page also is where one would look to tweak various  
plotting parameters, since those are better explained there.
Tom
#
You should provide raw data to boxplot(), not summary stats.
If you want to input summary stats, there was a post some time ago on that:
http://finzi.psych.upenn.edu/Rhelp10/2010-September/251674.html
<\quoate>

Overwriting $stats did the job for me. I wanted to show the effect of using
different quantile computation methods. 

Thanks a lot to everybody for the quick answers!

Tom