# How to change a part of the BoxWhiskerChart?

My intention is to change the style of the bottom of the BoxWhisker Chart after drawing of the BoxWhiskerChart. For instance: lines of the BoxWhiskerChart are Thick but change to dotted bellow threshold=0.1.

The goal is to show that the part of the data is bellow the detection limit

My simple experiment

 data= RandomReal[{0, 1}, 1000];

BoxWhiskerChart[data, {{"Whiskers", If[# < 0.1, Dashed, Thick] &}}]


anyway don't work. But my ideal is be able to change the style of the entire part of graph bellow threshold - include whiskers, quantiles, outliers... if they are < threshold.

You can use a custom ChartElementFunction as follows:

ClearAll[cF]
cF[t_: 0][cedf_: "BoxWhisker", o : OptionsPattern[]] :=
ChartElementDataFunction[cedf, o][##] /.
l : Line[{l1 : {{x_, b_}, {x_, a_}}, l2 : {{x_, c_}, {x_, d_}}}] :>
{CapForm["Butt"],
Which[t <= a, l, t >= d, {Dashed, l},
t >= c, {Line[l2 /. c -> t], Dashed, Line[l2 /. d -> t], Line[l1]},
t <= b, {Line[l1 /. a -> t], Line[l2], Dashed, Line[l1 /. b -> t]},
True, {Line[l2], Dashing[{Small, Small}], Line[l1]}]} &


Examples:

data = RandomReal[{0, 1}, 1000];
BoxWhiskerChart[{data, 1.2 data}, {{"Whiskers", Thick}},
ChartElementFunction -> cF[.2][]]


 BoxWhiskerChart[{data, 1.2 data}, {{"Whiskers", Thick}},
ChartElementFunction -> cF[.9]["GlassBoxWhisker"], ChartStyle->"Rainbow"]


Update: Adding dashed edges below the threshold per Okkes's suggestion in the comments:

ClearAll[cF2]
cF2[t_: 0][cedf_: "BoxWhisker", o : OptionsPattern[]] := Module[{qt = Quartiles[#2]},
{CapForm["Butt"], ChartElementDataFunction[cedf, o][##] /.
l : Line[{l1 : {{x_, b_}, {x_, a_}}, l2 : {{x_, c_}, {x_, d_}}}] :>
Which[t <= a, l, t >= d, {Dashed, l},
t >= c, {Line[l2 /. c -> t], Dashed, Line[l2 /. d -> t], Line[l1]},
t <= b, {Line[l1 /. a -> t], Line[l2], Dashed, Line[l1 /. b -> t]},
True, {Line[l2], Dashed, Line[l1]}],
Which[t >= qt[[-1]], {EdgeForm[{Dashed, Thick, Black}], FaceForm[],
Polygon @ {{#[[1, 1]],  qt[[-1]]}, {#[[1, 1]], qt[[1]]},
{#[[1, 2]], qt[[1]]}, {#[[1, 2]], qt[[-1]]}}},
qt[[-1]] > t > qt[[1]], {Thick, Black,
Line @ {{#[[1, 1]], t}, {#[[1, 1]],  qt[[-1]]},
{#[[1, 2]], qt[[-1]]}, {#[[1, 2]], t}},
Dashed, Line @ {{#[[1, 1]], t}, {#[[1, 1]],
qt[[1]]}, {#[[1, 2]], qt[[1]]}, {#[[1, 2]], t}}},
True, {}]}] &


Example:

data = RandomReal[{0, 1}, 1000];
t = .85;
BoxWhiskerChart[{data, 1.5 data}, {{"Whiskers", Thick}},
GridLines -> {None, {t}},
ChartElementFunction -> cF2[t]["GradientScaleBoxWhisker", "ColorScheme" -> "Rainbow"],
ImageSize -> Large]


• This is good but not informative if val<0.5. Is it possible make dashed edge form for the box when val<0.5? Commented May 3, 2019 at 15:19
• @OkkesDulgerci, good point. It might be easier to use Gridlines->{None, {val}}. I will update with a version that adds dashed edges.
– kglr
Commented May 3, 2019 at 19:39
• @Okkes, please see the update.
– kglr
Commented May 3, 2019 at 20:41
• Looks great! Two more suggestion. Top of left box should be also dashed. Edge of right box should be solid when t>0.85 (including top)? Even fence could be dashed? Commented May 3, 2019 at 22:07