Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I would like a chart showing the median, 1/4, 3/4 quartiles, without the whiskers or fences. how can I achieve this? I cannot figure out how to turn off both the whiskers and the fences in the result of:

BoxWhiskerChart[RandomVariate[NormalDistribution[0, 1], 100]]

but doing so would do the trick.

share|improve this question
1  
This seems to be a work around: BoxWhiskerChart[RandomVariate[NormalDistribution[0, 1], 100],{{"Fences", 0, None}, {"Whiskers", Opacity[0]}}]. But it seems like there should be a cleaner way. –  Italianice Jun 19 at 17:14
    
I recommend you write up your solution as an answer. I think it's quite clean, and, I for one, will up-vote it. –  m_goldberg Jun 19 at 20:12

4 Answers 4

up vote 5 down vote accepted

One way to achieve the result is to hide the whiskers and fences:

BoxWhiskerChart[RandomVariate[NormalDistribution[0, 1], 100],
  {{"Fences", 0, None}, {"Whiskers", Opacity[0]}}]

enter image description here

This works, but it's a little bothersome to know the objects are hidden rather than absent.

share|improve this answer

An alternative approach is to remove the unwanted Lines through post-processing:

BoxWhiskerChart[RandomVariate[NormalDistribution[0, 1], {5, 100}], 
      ChartStyle -> "Pastel"] /. LineBox[{{{_, _}, {_, _}} ..}] :> {}

enter image description here

BoxWhiskerChart[RandomVariate[NormalDistribution[0, 1], {5, 100}], 
     ChartStyle -> "Pastel", BarOrigin -> Left] /. LineBox[{{{_, _}, {_, _}} ..}] :> {}

enter image description here

share|improve this answer

You can use the ChartElementFunction option to control how the chart is drawn:

BoxWhiskerChart[RandomVariate[NormalDistribution[0, 1], 100]]

enter image description here

draw[{{xmin_, xmax_}, {ymin_, ymax_}}, data_, rest___] :=
  With[
   {qs = Quantile[data, {1/4, 1/2, 3/4}]},
   Polygon[{
     {xmin, qs[[1]]}, {xmax, qs[[1]]},
     {Mean@{xmin, xmax}, qs[[2]]},
     {xmin, qs[[3]]}, {xmax, qs[[3]]}
     }]];
BoxWhiskerChart[RandomVariate[NormalDistribution[0, 1], 100], ChartElementFunction -> draw]

enter image description here

It would take a bit more code to duplicate the look of the default chart, namely the division between the two rectangles. You'd have to offset from the median when drawing rectangles because otherwise there would be no white space between them.

Your own suggestion is pretty practical, though.

share|improve this answer

Update 2

It's actually not hard to duplicate the default chart's look with ChartElementFunction. Just build two rectangles with a little offset between them.

boxes[{{xmin_, xmax_}, {ymin_, ymax_}}, data_, rest___] := 
 With[{qPts = Quantile[data, {1/4, 1/2, 3/4}]}, 
   {Rectangle[{xmin, qPts[[1]]}, {xmax, qPts[[2]]}],
    Rectangle[{xmin, qPts[[2]]}, {xmax, qPts[[3]]}],
    {Thick, White, Line[{{xmin, qPts[[2]]}, {xmax, qPts[[2]]}}]}}]

Column[
  (SeedRandom[1];
     BoxWhiskerChart[RandomVariate[NormalDistribution[Sequence @@ #], 100], 
       ChartElementFunction -> boxes,
       ImageSize -> Medium]) & /@ {{0, 1}, {1000, 100}, {0, 1000}}]

boxes

Note: mfvonh brought my attention to a scaling problem in my original post of this answer. I have replaced the non-scaling by a perturbation dy = .03 with an automatically scaling thick line. I tested the new algorithm over a range of means and standard deviations without seeing any problem.

share|improve this answer
    
My concern was that this approach doesn't seem to scale well. (E.g., with RandomVariate[NormalDistribution[1000, 100], 100]). I tried using coefficients also but couldn't find a robust solution. Any thoughts? –  mfvonh Jun 19 at 22:44
    
@mfvonh. Thanks for pointing out the scaling problem. I have modified my code to address the issue. –  m_goldberg Jun 19 at 23:39

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.