5
$\begingroup$

I am trying to create a stacked BarChart where each BarChart has different ChartLabels. Consider the following example:

BarChart[{{5, 6, 7, 5, 7}, {8, 5, 6, 7, 8}}, ChartLayout -> "Stacked",
  ChartLabels -> {Placed[{"One", "Two"}, Above], 
   Placed[{5, 6, 7, 5, 7}, Center]}]

enter image description here

But what I would like to have is separate labels for the segments in the two chart elements. The following image illustrates this:

enter image description here

I can't figure out how to do that using ChartLabels. When I try providing multiple lists for the chart labels it doesn't work.

$\endgroup$
  • $\begingroup$ Here it is BarChart[{{5, 6, 7, 5, 7}, {8, 5, 6, 7, 8}}, LabelingFunction -> (Placed[#1, Center] &), ChartLayout -> "Stacked"] $\endgroup$ – Öskå Sep 19 '13 at 13:55
  • $\begingroup$ possible duplicate of Label both sides in BarChart $\endgroup$ – Pinguin Dirk Sep 19 '13 at 14:02
  • $\begingroup$ Not sure if it is a dupe, have a look if it helps $\endgroup$ – Pinguin Dirk Sep 19 '13 at 14:03
6
$\begingroup$

This and this give the answer by using LabelingFunction. Thus you can use

BarChart[{{5, 6, 7, 5, 7}, {8, 5, 6, 7, 8}}, 
  LabelingFunction -> (Placed[#1, Center] &), 
  ChartLayout -> "Stacked"]

And have:

Tada!

$\endgroup$

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.