# Label all components of BoxWhiskerChart with corresponding data

I work with BoxWhiskerCharts at the moment. They code looks like this:

data = RandomInteger[5, 50];
chart = BoxWhiskerChart[{data},
{{"MedianMarker", 1, Black},{"MeanMarker", 1, White}, {"Outliers"}},
ChartLabels -> Placed[{"data"}, Above]]


Now I would like to label the whiskers, both markers (mean and median), and the minimum/maximum of the box with the corresponding values. In the end it should look similar to this (quick and dirty) Excel example:

What I want is circled red in the picture. I do not need to label each and every data point. How can I accomplish that with Mathematica?

You can use a custom ChartElementFunction to add labels at desired positions:

ClearAll[cef]
cef[df_: "BoxWhisker"][off_: 5] := Module[{x = #[[1]],
q = Quartiles @ #2, m = Round[Mean @ #2, .1], minmax = MinMax@#2},
{ChartElementDataFunction[df][##], Darker @ ChartingChartStyleInformation["Color"],
FontWeight -> Bold, FontSize -> Medium,
Text[m, Offset[{-off, 0}, {x[[1]], m}], {1, 0}],
Text[#, Offset[{off, 0}, {x[[2]], #}], {-1, 0}] & /@ q,
Text[#, Offset[{-off, 0}, {x[[2]], #}], {-1, 0}] & /@ minmax}] &


Examples:

BoxWhiskerChart[{data}, {{"MedianMarker", 1, Black}, {"MeanMarker", 1,
White}, {"Outliers"}}, ChartElementFunction -> cef[][]]


BoxWhiskerChart[{{data, 1 + data}, {2 + data, 3 + data}},
{{"MedianMarker", 1, Black}, {"MeanMarker", 1, White}, {"Outliers"}},
ChartElementFunction -> cef["GlassBoxWhisker"][],  BarSpacing -> {Large, Large}]


• Thank you, that works like a charm. Quick note for other users like me since it took me some minutes: of course you have to adjust the rounding parameter (m = Round[Mean @ #2, .1]`) to your data. Im working with quite small numbers which made it look like it is messing with the plot range. Commented Nov 25, 2018 at 20:53