2
$\begingroup$

Given

ClearAll[a, b, c];
a = {1, 2, 3};
b = {4, 1, 6, 3, 2};
c = {0, 9, 1, 2, 8};
BarChart[Append[#, Total@#] & /@ {a, b, c}, ChartStyle -> {"Pastel", None},
ChartLabels -> {"a", "b", "c", "d", "e", "T"}
]

I get:

enter image description here

As seen from the bar chart above, T denotes Total. The first list shows T as d, which is wrong. Secondly, the bars corresponding to Total should be Black (or any other color not used in the Bar chart) for all three lists. Most important of all, all these revisions should be made automatically when I change the length of the lists a, b, c.

Thanks for your help.

$\endgroup$

1 Answer 1

4
$\begingroup$

The easiest is probably to use wrapper-style Labeled[...] and Style[...] specifications as follows:

BarChart[
 Append[#, Labeled[Style[Total@#, Black], "T"]] & /@ {a, b, c},
 ChartStyle -> {"Pastel", None},
 ChartLabels -> {"a", "b", "c", "d", "e"}
 ]

enter image description here

Note how the style & label specified for the total bar overrides any other values, giving you the desired result.

$\endgroup$
1
  • $\begingroup$ Thanks for the code. I forgot to ask about how to put a Black horizontal line for Mean value of each list rather than Total. Sorry, this might be another question if you think so. Now I created a Manipulate for two options Total, Mean, which works fine. $\endgroup$ Commented Sep 14, 2023 at 14:23

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.