6
$\begingroup$

How can I use custom color for fence, whisker and outliers.

Here is my MWE

 col = {Red, Darker@Green, Blue, Orange}; SeedRandom@5;
    data = Table[
       RandomReal[BetaDistribution[\[Alpha], 1.5], 
        100], {\[Alpha], {6, 3, 7, 8}}];
    BoxWhiskerChart[data, {"Outliers", {"MedianMarker", White}}, 
     ChartStyle -> col]

enter image description here

What I want is this kind of chart.

enter image description here

$\endgroup$

1 Answer 1

10
$\begingroup$

Use a custom ChartElementFunction and pass the color information as metadata using Thread[data->col] as the first argument in BoxWhiskerChart:

ClearAll[cef]   

 cef = {EdgeForm[#3[[1]]], FaceForm[], 
    ChartElementData["BoxWhisker"][##] /. {l_Line :> {#3[[1]], l}, 
      GrayLevel[0] -> #3[[1]]}} &;
BoxWhiskerChart[
 Thread[data -> col], {"Outliers", {"MedianMarker", White}}, 
 ChartStyle -> col, ChartElementFunction -> cef]

enter image description here

ClearAll[cef2] 
cef2 = {EdgeForm[#3[[1]]], FaceForm[#3[[1]]], 
    ChartElementData[
       "BoxWhisker"][##] /. {GrayLevel[0 | .5] -> #3[[1]]}} &;
BoxWhiskerChart[
 Thread[data -> col], {"Outliers", {"MedianMarker", White}}, 
 ChartStyle -> col, ChartElementFunction -> cef2]

enter image description here

$\endgroup$
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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