# How to center the labels on a bar chart so they are directly under their respective bar? [duplicate]

I am using v8 and have the following code:

BarChart[#, ChartStyle -> "Pastel",
ChartLabels -> (Rotate[#, Pi/3] & /@ #2)] & @@ Transpose[totals4]


It creates a bar chart and places the labels at a angel that slopes from the bottom, up to the right (slants to the right). The labels are not centered with the bars. In other words if there are 10 vertical bars, the corresponding labels are not centered, rather they are shifted to the right.

How can I center the labels?

How can I have the labels slant to the left?

Example of how it looks currently:

Thank you for any help.

-

## marked as duplicate by Mr.Wizard♦Jul 7 '13 at 17:12

They look pretty centered under the bars to me. To rotate them the opposite direction (to the left), use ChartLabels -> (Rotate[#, -Pi/3] & /@ #2). –  kale Jun 3 '13 at 2:30
I think the most reasonable interpretation is that the uppermost part of the label should start/end at the center of its bar. –  Pickett Jun 3 '13 at 3:39

With the interpretation by Anon, here is a solution that places the labels below the bars with their top right corners aligned to the center:

totals4 =
Transpose@{RandomInteger[{0, 60}, 5], CountryData[][[1 ;; 5]]};

BarChart[#, ChartStyle -> "Pastel",
ChartLabels -> (Placed[
Rotate[Style[#, Blue], Pi/3] & /@ #2, {{.5, 0}, {1, 1}}])] & @@
Transpose[totals4]


In the Placed command, the relative positions are numeric, because symbols like Center don't seem to work in version 8.

The second position argument {1, 1} is the top right corner of the rotated text label. To slant the labels in the opposite direction, I assume you want the following:

BarChart[#, ChartStyle -> "Pastel",
ChartLabels -> (Placed[
Rotate[Style[#, Blue], -Pi/3] & /@ #2, {{.5, 0}, {0, 1}}])] & @@
Transpose[totals4]


The reading direction is still mostly left to right, so that now we want to align the left top of the label text with the center of the bar. That's why I changed the second position argument of Placed to {0, 1}.

-
Is there a way to do something this simply for FrameTicks labels? I have contrived a solution but it's not pretty. –  Mr.Wizard Jun 3 '13 at 5:36
@Mr.Wizard Do you mean FrameTicks in general, or specifically in Charts? I've never tried Placed outside charts or graphs, I think... –  Jens Jun 3 '13 at 5:54
@Mr.Wizard Probably the answer is no; the Placed objects are realized as regular Inset boxes, and the tick labels aren't. Inset has the two pos and opos arguments, but I don't see anything along those lines for tick labels, unless you either wrap them in Graphics or roll your own from scratch. Well, and of course there is always a chance that Wizardry finds an alternate route... –  Jens Jun 3 '13 at 6:13
Thank you this works, however is there a way that the labels can have the same color as the bars? Again thank you. –  sente Jun 3 '13 at 9:42