4
$\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$
  • $\begingroup$ No, the second labels on the plot c1 c2 c3 should be c4 c5 c6. $\endgroup$ – Mockup Dungeon Sep 19 '16 at 12:24
  • 3
    $\begingroup$ Placed[{{"c1", "c2", "c3"}, {"c4", "c5", "c6"}}, Axis] $\endgroup$ – corey979 Sep 19 '16 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$ – Mockup Dungeon Sep 19 '16 at 12:32
  • $\begingroup$ @corey979 I just tried it with BoxWhiskerChart – which provides a different result. $\endgroup$ – Mockup Dungeon Sep 19 '16 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 '16 at 12:49
4
$\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$
  • $\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$ – Mockup Dungeon Sep 19 '16 at 13:03
  • $\begingroup$ @MockupDungeon My edit should address your comment. $\endgroup$ – Karsten 7. Sep 19 '16 at 13:09
  • $\begingroup$ Great! Thanks a lot. That's working. I'll now try and understand the labelling function command. $\endgroup$ – Mockup Dungeon Sep 19 '16 at 13:30
  • $\begingroup$ @MockupDungeon As a tip for that: Use {##} to see what information is available to LabelingFunction. $\endgroup$ – Karsten 7. Sep 19 '16 at 13:43
  • $\begingroup$ – Thanks. I'll try this out. $\endgroup$ – Mockup Dungeon Sep 19 '16 at 18:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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