Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

In the bar chart (with negative values)

BarChart[{{1, 2, 3}, -{4, 5, 6}}, 
 ChartLabels -> {Placed[{"r1", "r2"}, Above], 
   Placed[{"c1", "c2", "c2"}, Below]}]

enter image description here

the bar and group labels can be placed above and below the bars.

How can I place the bar and group labels on the upper and lower frame axes like in the paired bar chart

PairedBarChart[{Range[4], Range[4]/2}, {Range[4], Range[4]/2}, 
 ChartLabels -> {Placed[{"pair1", "pair2"}, Above], 
   Placed[{"g1", "g2"}, "LeftAxis"], 
   Placed[{"a", "b", "c", "d"}, "RightAxis"]}]

enter image description here

where the labels are placed to the left and right axis by using Placed[{"g1", "g2"}, "LeftAxis"] and Placed[{"a", "b", "c", "d"}, "RightAxis"]? Unfortunately, this doesn't work with BarChart and "TopAxis" nor "BottomAxis".

share|improve this question

3 Answers 3

up vote 2 down vote accepted

Post-processing to account for BarSpacing settings when placing bar labels on frameticks (as in @bensheperd's answer),

dta = {{1, 2, 3}, -{4, 5, 6}};
bc = BarChart[dta, BarSpacing -> {.3, .6}, ImageSize -> 450,
ChartLabels -> {Placed[{"r1", "r2"}, Axis], Placed[{"c1", "c2", "c3"}, Above]}];
tks = Riffle[GatherBy[ Cases[bc, 
  Text[t_, Offset[{_, _}, {x_, y_}] | {x_, y_}, ___] :> {x, ToString@t}, {0, Infinity}],
  StringTake[Last[#], 1] &],
  {Automatic, Automatic}];
bc2 = BarChart[dta, BarSpacing-> {.3, .6}, ImageSize ->450,Frame-> True, FrameTicks -> tks];
Row[{bc, bc2}]

enter image description here

share|improve this answer

This first solution is not exactly what you're looking for, but it gets close:

BarChart[{{1, 2, 3}, -{4, 5, 6}}, 
  ChartLabels -> {Placed[{"r1", "r2"}, {.5, 2}], 
  Placed[{"c1", "c2", "c2"}, Axis]}]

enter image description here

To get the correct representation you need to tweak a bit some values:

BarChart[{{1, 2, 3}, -{4, 5, 6}}, 
  ChartLabels -> {Placed[{"r1", "r2"}, {.5, 2}], 
  Placed[{"c1", "c2", "c2"}, {{0, 0}, {-2.2, 11}}]}]

enter image description here

Update

If you also need the axes on top and on bottom of the figure, you might try this approach (similar to the solution provided by benshepherd):

BarChart[{{1, 2, 3}, -{4, 5, 6}}, 
  FrameTicks -> {Transpose[{Range[.7, 6.3, (6.3 - .7)/5], {"c1", "c2", 
  "c3", "c1", "c2", "c3"}}], 
  Automatic, {{.7 + (6.3 - .7)/5, "r1"}, {6.3 - (6.3 - .7)/5, "r2"}},
  Automatic}, Frame -> {{True, False}, {True, True}}]

enter image description here

share|improve this answer
    
Is there a way to print axes like in the PairedBarChart? –  Robinaut Mar 7 '13 at 11:12
    
Please, see update. –  VLC Mar 7 '13 at 11:27
    
Note, that this won't work for BoxWhiskerChart, as it seems to ignore FrameTicks specifications. –  István Zachar Dec 16 at 11:25

No, there doesn't appear to be a valid argument for Placed - Mathematica wants to place your label relative to the bar.

To get labels on the axes, I think you'd have to use FrameTicks:

BarChart[{{1, 2, 3}, -{4, 5, 6}}, 
  FrameTicks -> {Automatic, Automatic, 
   Transpose@{Range@6, {"c1", "c2", "c3", "c1", "c2", "c3"}}, 
   Automatic}, Frame -> True]
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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