1
$\begingroup$

I'd like to plot a bar chart with two data sets $\{a_1,a_2,\dots,a_n\}$ and $\{b_1,b_2,\dots,b_n\}$ in such a way that the columns appear in the order $\{a_1,b_1,a_2,b_2,\dots,a_n,b_n\}$ and that each pair of columns is labelled with labels $\{\ell_1,\ell_2,\dots,\ell_n\}$.

Here's a fairly minimal working non-example:

BarChart[Transpose[{{1, 2, 3, 4}, {1, 1, 3, 5}}], ChartLabels -> {"A", "B", "C", "D"}]

which plots this

wrongly labelled bar chart

whereas I would like the labels to be A B C D and, if possible, centred under each pair of columns.

Many thanks in advance for your help.

$\endgroup$
6
$\begingroup$

Try this:

BarChart[Transpose[{{1, 2, 3, 4}, {1, 1, 3, 5}}], ChartLabels -> {{"A", "B", "C", "D"}, None}]

which produces this:

enter image description here

See the ChartLabels section of BarChart for similar tricks.

$\endgroup$
  • $\begingroup$ Is there a way to do this with just two datasets, wherein there's no particular pairing between the elements as above? I.e., I'd like to have something like two side-by-side datasets, {1,2,3,4} and {5,6,7,8}, with the labels "Dataset 1" and "Dataset 2" underneath each one. $\endgroup$ – Ben Kalziqi Jun 6 '18 at 21:26

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.