# BoxWhiskerChart - 10-90th percentile instead of min - max

I am trying to draw a custom BoxWhiskerChart with alternative values determining fences. I have data that has a lot of outliers and I have to compare it to another chart that has 10-90th percentile instead of standard min/max.

How would I go about it?

• Hi ! Do you have any code you can share with us ? Jul 16 '14 at 21:59
• Hi,data = RandomVariate[NormalDistribution[0, 1], 200]; BoxWhiskerChart[data] is the function I am using. Nothing more fancy about it. I am wondering if there is a way to modify the specification of what is a fence - ie instead of min-max - I would like it to be 10-th and 90th percentile.
– jps
Jul 16 '14 at 22:07
• I would imagine it is possible to draw boxes, I am not sure how to use mathematica function draw[] to plot fences.
– jps
Jul 16 '14 at 22:10

With the data beeing

data = RandomVariate[NormalDistribution[0, 1], 200];


the range of the box specified to be one sigma (approx. 68.3 %tile range) by

sigma=Erf[1/Sqrt[2]]


and a limit for the fences defined to be 10 %

fencesLimit = 0.1


we can plot a BoxWhiskerChart using:

BoxWhiskerChart[data, "Median",
Method ->
"BoxRange" ->
(Quantile[#, {fencesLimit, (1 - sigma)/2, 1/2, (1 + sigma)/2, 1 - fencesLimit},
{{1/3, 1/3}, {0, 1}}] &)]


This BoxWhisker is median centered, has a box range of one sigma, a lower fence at the 10 percentile, and an upper fence at the 90 percentile.
You can find in the documentation of Quantile how to choose another centering.

Here a plot of this BoxWhiskerChart:

With some additional styling and as a function with optional arguments:

bwChart[data_, br_: Erf[1/Sqrt[2]], flimit_: 0.1] :=
BoxWhiskerChart[data,
{{"MedianMarker", 1, Directive[Thickness[0.01], Blue]}, {"MedianNotch", 0.5, Gray}},
Method -> "BoxRange" -> (Quantile[#, {flimit, (1 - br)/2, 1/2, (1 + br)/2, 1 - flimit},
{{1/3, 1/3}, {0, 1}}] &),
BarSpacing -> None, AspectRatio -> 0.7, BarOrigin -> Left,
ChartElementFunction -> "GlassBoxWhisker", ChartStyle -> 6]

bwChart[data]


Using Mathematica version 11.0.0 the output of bwChart[data] is

A direct comparison of the same data as a 10th to 90th %tile BoxWhiskerChart with an "Outliers" and a standard min/max BoxWhiskerChart.

data = RandomVariate[NormalDistribution[0, 1], 200];

Show[{
BoxWhiskerChart[{data, Null, Null}, "Outliers",
Method ->
{"BoxRange" -> (Quantile[#, {10/100, 1/4, 1/2, 3/4, 90/100}, {{1/2, 0}, {0, 1}}] &)}],
BoxWhiskerChart[{Null, data, Null}, "Outliers"],
BoxWhiskerChart[{Null, Null, data}]
}]


• (+1) Thank you! Spent hours to make BoxRange work as an option :)
– kglr
Jul 17 '14 at 2:08
• @Masi Did you use bwChart[data] to produce the output? It wasn't part of the posted code block before my latest edit, which also shows the output I get using version 11. If you are still having problems, please be more specific of what you cannot reproduce. Sep 27 '16 at 11:08
• @Masi For me replacing data with {data1, data2} does produce the expected output. Here is a screen snipped of the in- and output I used to test it. Did I misunderstand you or does that solve your problem? (I'm not sure what you mean with "with other data sources in the same figure".) Sep 27 '16 at 14:00
• @Masi Please see my edit. I'd use Show to combine these different kinds of BoxWhiskerCharts into one graph. Sep 27 '16 at 15:56
• @Masi If your data doesn't have any outliers, then that is expected. Also having very few data points can result in all BoxWhiskerCharts looking the same. Here is one example. The relatively big boxes in your image certainly makes it look like you don't have a lot of data point and that they are relative uniformly distributed. Sep 27 '16 at 17:41