10
$\begingroup$

I have labeled the name(A,B,C) of each row on the left and value of each item , is there any way to put the total number(6,7,5) of each row on the right side without changing other labels?

BarChart[{{1, 2, 3}, {2, 4, 1}, {3, 1, 1}}, BarOrigin -> Left, 
 ChartLayout -> "Stacked", BarSpacing -> 0.5, 
 ChartLabels -> {Placed[{"A", "B", "C"}, Before], None}, 
 LabelingFunction -> (Placed[#1, Center] &)]

enter image description here

$\endgroup$

1 Answer 1

17
$\begingroup$

Maybe this helps:

BarChart[#, BarOrigin -> Left, ChartLayout -> "Stacked", 
 BarSpacing -> 0.5, 
 ChartLabels -> {Placed[{{"A", "B", "C"}, {Total@#[[1]], 
 Total@#[[2]], Total@#[[3]]}}, {Before, After}], None}, 
 LabelingFunction -> (Placed[#1, Center] &)] &@{{1, 2, 3}, {2, 4, 1}, {3, 1, 1}}

EDIT: slightly cleaner:

BarChart[#, BarOrigin -> Left, ChartLayout -> "Stacked", 
 BarSpacing -> 0.5, 
 ChartLabels -> {Placed[{{"A", "B", "C"}, Total@#}, {Before, After}], None}, 
 LabelingFunction -> (Placed[#1, Center] &)] &@{{1, 2, 3}, {2, 1, 1}, {3, 1, 1}}

enter image description here

$\endgroup$
2
  • $\begingroup$ Your answer is excellent! $\endgroup$ Commented Jan 12, 2013 at 1:29
  • $\begingroup$ @Mr.Wizard - thanks! #paradox2 - glad it helped! $\endgroup$ Commented Jan 13, 2013 at 7:45

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.