1
$\begingroup$

I have the following data:

data = {{1.2, 1.1, 1.4, 1.4, 1.5, 1.6, 1.2, 1.1, 1}, {1.3, 1.4, 1.2, 
1, 1.1, 0.8, 1.1, 1.2, 1}};

and I would like to make a BarChart where each bar has a label with the corresponding value. Basically, I would like to add Labels to the bars in:

BarChart[Thread@data, ChartLabels -> {Placed[Range[1, 9], Below], None},
Frame -> True,FrameTicks -> {False, True},
BaseStyle -> {Large, FontFamily -> "Arial", Black},
BarSpacing -> {0, 0.8},PlotRange -> {All, {-0.3, 2}}, 
PlotRangePadding -> {0.8, {0, 0}},AspectRatio -> 0.4,ImageSize -> 800,
FrameStyle->Directive[Black, AbsoluteThickness[3]]]

How to manage this?

Also, I would like to add a legend for the two colors.

$\endgroup$
1
$\begingroup$

Wrap each data point with Labeled and add the option ChartLegends -> {"Group A", "Group B"}

BarChart[Labeled[#, Style[#, 14], Center] & /@ # & /@ Thread @ data, 
 ChartLabels -> {Placed[Range[1, 9], Below], None}, Frame -> True, 
 FrameTicks -> {False, True}, 
 BaseStyle -> {Large, FontFamily -> "Arial", Black}, 
 BarSpacing -> {0, 0.8}, PlotRange -> {All, {-0.3, 2}}, 
 PlotRangePadding -> {0.8, {0, 0}}, AspectRatio -> 0.4, 
 ImageSize -> 800, 
 FrameStyle -> Directive[Black, AbsoluteThickness[3]],
 ChartLegends -> {"Group A", "Group B"}]

enter image description here

Or, keep Thread @ data as the first argument and add the option

LabelingFunction -> (Placed[Style[#, 14], Center] &)

to get the same picture.

$\endgroup$

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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