6
$\begingroup$

I try and make a complex labelling on a BoxWhiskerChart. However, the solution I tried isn't working properly as

BoxWhiskerChart[{{{2, 4, 3, 5, 7, 5, 4, 3, 2}, {3, 4, 5, 2, 1}, {1, 5,
     3, 2, 5, 7}}, {{2, 4, 3, 5, 7, 5, 4, 3, 2}, {3, 4, 5, 2, 1}, {1, 
    5, 3, 2, 5, 7}}, {{2, 4, 3, 5, 7, 5, 4, 3, 2}, {3, 4, 5, 2, 
    1}, {1, 5, 3, 2, 5, 7}}}
 , ChartLabels -> {Placed[{"a", "b", "c"}, Axis], 
   Placed[{{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}, After]}
 , ChartStyle -> {"Pastel", None}
 , BarOrigin -> Left
 ]

results in

enter image description here

$\endgroup$
8
  • $\begingroup$ No, the second labels on the plot c1 c2 c3 should be c4 c5 c6. $\endgroup$ Sep 19, 2016 at 12:24
  • 3
    $\begingroup$ Placed[{{"c1", "c2", "c3"}, {"c4", "c5", "c6"}}, Axis] $\endgroup$
    – corey979
    Sep 19, 2016 at 12:24
  • $\begingroup$ @corey979 embarrassing – I tried this before and it didn't work ... I must have made a simple syntax error. Apologies. Working now ... $\endgroup$ Sep 19, 2016 at 12:32
  • $\begingroup$ @corey979 I just tried it with BoxWhiskerChart – which provides a different result. $\endgroup$ Sep 19, 2016 at 12:41
  • 2
    $\begingroup$ Your question is very poorly posed. Is it about bar charts as the title implies, or is it box-whisker charts? $\endgroup$
    – m_goldberg
    Sep 19, 2016 at 12:49

1 Answer 1

6
$\begingroup$

For the BoxWhiskerChart you can use

BoxWhiskerChart[{{{2, 4, 3, 5, 7, 5, 4, 3, 2}, {3, 4, 5, 2, 1}, {1, 5, 3, 2, 
    5, 7}}, {{2, 4, 3, 5, 7, 5, 4, 3, 2}, {3, 4, 5, 2, 1}, {1, 5, 3, 2, 5, 
    7}}, {{2, 4, 3, 5, 7, 5, 4, 3, 2}, {3, 4, 5, 2, 1}, {1, 5, 3, 2, 5, 7}}}
 , ChartLabels -> {Placed[{"a", "b", "c"}, Axis], None}
 , LabelingFunction -> (Placed[#2.{3, 1} - 3, After] &)
 , ChartStyle -> {"Pastel", None}, BarOrigin -> Left]

Out

or

BoxWhiskerChart[{{{2, 4, 3, 5, 7, 5, 4, 3, 2}, {3, 4, 5, 2, 1}, {1, 5, 3, 2, 
    5, 7}}, {{2, 4, 3, 5, 7, 5, 4, 3, 2}, {3, 4, 5, 2, 1}, {1, 5, 3, 2, 5, 
    7}}, {{2, 4, 3, 5, 7, 5, 4, 3, 2}, {3, 4, 5, 2, 1}, {1, 5, 3, 2, 5, 7}}}
 , ChartLabels -> {Placed[{"a", "b", "c"}, Axis], None}
 , LabelingFunction -> (Placed[Extract[{{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}, #2], After] &)
 , ChartStyle -> {"Pastel", None}, BarOrigin -> Left]
$\endgroup$
5
  • $\begingroup$ Looks good – however, do I read this correctly that this only works for the numbers? What if 1,2,3,4,... is an arbitrary string list? E.g. {"a","b","c",...} instead of {1,2,3,4...} $\endgroup$ Sep 19, 2016 at 13:03
  • $\begingroup$ @MockupDungeon My edit should address your comment. $\endgroup$
    – Karsten7
    Sep 19, 2016 at 13:09
  • $\begingroup$ Great! Thanks a lot. That's working. I'll now try and understand the labelling function command. $\endgroup$ Sep 19, 2016 at 13:30
  • $\begingroup$ @MockupDungeon As a tip for that: Use {##} to see what information is available to LabelingFunction. $\endgroup$
    – Karsten7
    Sep 19, 2016 at 13:43
  • $\begingroup$ – Thanks. I'll try this out. $\endgroup$ Sep 19, 2016 at 18:56

Your Answer

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

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