1
$\begingroup$

I want to make the following bar chart, but with relative abundances on top of the chart labels. I get the absolute numbers, but not the relative abundances:

data = {{43, 14}, {193, 158}, {37, 18}, {12, 3}, {5, 1}, {4, 0}};

BarChart[data
 , LabelingFunction -> (Placed[#, Above] &)
 ]

I get it to work if I have only one bar per category, but not with two bars per category, because I don't know how to make the division inside the LabelingFunction separate for each category:

data = {43, 193, 37, 12, 5, 4};

BarChart[data
 , LabelingFunction -> (Placed[N[#/Total@data], Above] &)
 ]
$\endgroup$
1
$\begingroup$
labeleddata = Transpose@Map[Labeled[#, Rotate[#2, Pi/2], Above] & @@ # &, 
                  Transpose /@ ({#, N@Normalize[#, Total]} & /@ Transpose@data), {2}]; 

BarChart[labeleddata]

enter image description here

or

labeleddata2 = Transpose[Labeled[#, Rotate[#2, Pi/2], Above] & @@@ # & /@ 
                          (Transpose /@ ({#, N@Normalize[#, Total]} & /@ Transpose@data))];

BarChart[labeleddata2]
(* same picture *)
$\endgroup$
  • $\begingroup$ Great! Thanks a lot. I am sort of glad there isn't a simple answer. $\endgroup$ – Mockup Dungeon Jan 29 '15 at 12:24

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.