# LabelingFunction in BarChart displays bar-values below x-axis

I'm trying to visualize some data using a BarChart[] in Mathematica.

The data should be placed (centered) inside the bars - except the bar is too small. In this case the date should be written above the bar.

My command for creating the BarChart:

BarChart[{
{0.123, 0.492}, {2.865, 0.055},
{1.03, 1.084}, {4.282, 0.053}
}, AxesLabel -> {"", "Value"},
ChartLabels -> {
Placed[{
"data1", "data2",
"data3", "data4"
}, {{0.5, 0}, {0.8, 1.2}}, Rotate[#, (1.75/7) Pi] &],
Placed[{"", ""}, Above]},
LabelingFunction -> (Placed[#1, {{0.5, 0.5}, {0.5, 0.5}},
Rotate[#, 0.5 Pi] &] &),
ChartLegends -> {"⌀", "σ"}]


and the result:

As you can see the 1st., 4th and 8th value are even below the x-axis.

Is there some way to add some kind of 'exception' for this kind of bars?

• If you just want to modify bar charts occasionally, you can just double click on a label and move it. Commented Jul 23, 2015 at 12:26

A small change to the LabelingFunction seems to do the trick:

BarChart[{{0.123, 0.492}, {2.865, 0.055}, {1.03, 1.084}, {4.282, 0.053}},
AxesLabel -> {"", "Value"},
ChartLabels -> {Placed[{"data1", "data2", "data3", "data4"},
{{0.5, 0}, {0.8, 1.2}}, Rotate[#, (1.75/7) Pi] &],
Placed[{"", ""}, Above]},
LabelingFunction -> (
Placed[Rotate[#, 0.5 Pi], If[#1 > 0.5, Center, Above]] &),
ChartLegends -> {"⌀", "σ"}
]


For now, the term 0.5 (the smallest bar size that can have a label inside) needs to be set manually.

• I made a couple of changes; hope you don't mind! Commented Jul 23, 2015 at 13:30
• Exactly what I was looking for. Thank you very much. Commented Jul 23, 2015 at 13:34
• @Mr.Wizard Fine. It's clearer this way at the cost of not being able to fine tune the positioning. Commented Jul 23, 2015 at 15:31