2
$\begingroup$

How to be able to make whiskers and fences of red boxes red, and of blue boxes blue in the following example with grouped boxplots?

xdata = {{"A", {1, 2, 5}}, {"B", {5, 7, 2, 2, 5}}, {"C", {3, 2, 5, 7}}};
ydata = {{"A", {7, 2}}, {"B", {7, 2, 5}}, {"C", {6, 7, 3}}};

labels = {xdata[[All, 1]], None}

xdata = xdata[[All, 2]];
ydata = ydata[[All, 2]];

data = Transpose@{xdata, ydata}

style = Sequence[{
  {"Whiskers", Dashed},
  {"Outliers", None},
  {"MedianMarker", 1, Directive[Thick, White]}},
  ChartStyle -> {Red,BLue},
  ImageSize -> Medium,
  ChartLegends -> {"x", "y"},
  ChartLabels -> labels];

BoxWhiskerChart[data, style]
```
$\endgroup$
1
  • $\begingroup$ Welcome to Mathematica.SE! I suggest the following: 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Take the tour! 3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! $\endgroup$
    – Michael E2
    Mar 20 at 18:17
1
$\begingroup$

1. You can post-process BoxWhiskerChart output to remove the default fence and whisker colors:

BoxWhiskerChart[data, style] /. g_GraphicsGroup :> (g /. GrayLevel[Except[1]] -> {})

enter image description here

Note: In versions 11.3.0 and older, replace g_GraphicsGroup with g_GraphicsGroupBox.

2. Alternatively, you can add a custom ChartElementFunction to style as follows:

style2 = Sequence[{{"Whiskers", Dashed}, {"Outliers", None}, 
    {"MedianMarker", 1, Directive[Thick, White]}}, 
   ChartStyle -> {Red, Blue}, ImageSize -> Medium, 
   ChartLegends -> {"x", "y"}, ChartLabels -> labels, 
   ChartElementFunction -> (ChartElementData["BoxWhisker"][##] /. 
     GrayLevel[Except[1]] -> {} &)];

BoxWhiskerChart[data, style2]

enter image description here

Use ChartStyle -> "Rainbow" instead of ChartStyle -> {Red, Blue} to get

enter image description here

$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.