6
$\begingroup$

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".

$\endgroup$
3
$\begingroup$

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

$\endgroup$
7
$\begingroup$

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

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

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]
$\endgroup$

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.