# Custom BoxWhisker Plot

I’d like to figure out how I can show my entire dataset overlaid on a box whisker plot.

data = {{0.763983, -1.11426, 1.05153, -0.0369066, 1.1571, 0.834856, 0.146695,
0.100646, 2.69399, 0.425281}, {0.506237, 1.05127, 1.58117,
0.976295, 1.62204, 1.39005, 1.62387, 1.36098, 1.83858,
0.709489}, {-1.62786, 0.947744, 4.50628, 0.444416, 1.30947, 0.60594,
0.890642, 4.04505, 4.57667, 0.781394}}

The following allows me to show Outliers overlaid on the plot. How would I go about overlaying all of the datapoint on the plot?

BoxWhiskerChart[data, {"Notched", {"MedianMarker", Blue}, {"Outliers",
"\[EmptySmallCircle]", Red}},ChartLabels -> {"X", "Y", "Z"}]
• Show[BoxWhiskerChart[data], ListPlot[MapIndexed[{#2[[1]], #1} &, data, {2}]]] Commented Feb 17, 2014 at 22:08
• Thanks this works well…! Still learning the intricacies of Mathematica’s plotting routines
– Pam
Commented Feb 18, 2014 at 14:11
• Belisarius, can you explain how the MapIndexed trick works. I seem to have a hard time understanding it. Would appreciate some help…..
– Pam
Commented Feb 18, 2014 at 14:15
• Can you post an answer so that I can acknowledge this as an answer?
– Pam
Commented Feb 18, 2014 at 14:16

One way to do it is:

Show[BoxWhiskerChart[data], ListPlot[MapIndexed[{#2[[1]], #1} &, data, {2}]]]

MapIndexed operates just like Mapbut gives you a second argument which is the index of the list element you're getting each time.

• I don’t still quite get {#2[[1]], #1} part of it… I know they stand for slot sequences but still don’t see how they map to the data…
– Pam
Commented Feb 18, 2014 at 15:08
• @Pam Try MapIndexed[f, {a,b}] to see that #2[[1]] takes values 1, 2 and #1 takes values a, b Commented Feb 18, 2014 at 15:13

You can overlay your data and BoxWhiskerChart using a custom ChartStyleFunction. The first example ceF1 combines built-in ChartElementDataFunction["BoxWhisker"] with the graphics primitives obtained from ListPlot of the data. The second and third examples use the buit-in functions "PointDensity" and "LineDensity" in place of ListPlot.

ceF1 = {PointSize[.015], ChartElementDataFunction["BoxWhisker"][##],
Darker[Darker@ChartingChartStyleInformation["Color"]]][[1]]} &;

ceF2 = {PointSize[.05], FaceForm[Opacity[.3]],
ChartElementDataFunction["PointDensity", "PointStyle" ->
Directive[Darker[ChartingChartStyleInformation["Color"]],  PointSize[Large]]][##],
Opacity[.8], ChartElementDataFunction["BoxWhisker"][##]} &;

ceF3 = {Thick, Darker[Charting`ChartStyleInformation["Color"]],
ChartElementDataFunction["LineDensity"][##], Opacity[.8],
ChartElementDataFunction["BoxWhisker"][##]} &;

Examples:

Panel[BoxWhiskerChart[data, {"Notched", {"MedianMarker", Blue},
{"Outliers", "\[EmptyCircle]", Directive[15, Bold, Red]}},
ChartLabels -> {"X", "Y", "Z"}, ChartStyle -> 63,
ImageSize -> 320, ChartElementFunction -> ToExpression[#]],
Style["ChartElementFunction->" <> #, 18, "Panel"], Top] & /@
{"ceF1", "ceF2", "ceF3"} // Row