# BoxWhiskerChart without whiskers

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.

• 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. – mdeceglie Jun 19 '14 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 '14 at 20:12

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]}}]


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

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

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


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


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

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


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]


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.

### 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}}]


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.

• 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 '14 at 22:44
• @mfvonh. Thanks for pointing out the scaling problem. I have modified my code to address the issue. – m_goldberg Jun 19 '14 at 23:39