In How to | Add Error Bars to Charts and Plots in the Mathematica documentation, a function ErrorBar
is given:
errorBar[type_: "Rectangle"][{{x0_, x1_}, {y0_, y1_}}, value_, meta_] :=
Block[{error},
error = Flatten[meta];
error = If[error === {}, 0, Last[error]];
{ChartElementData[type][{{x0, x1}, {y0, y1}}, value, meta],
{Black, Line[{
{{(x0 + x1)/2, y1 - error}, {(x0 + x1)/2, y1 + error}},
{{1/4 (3 x0 + x1), y1 + error}, {1/4 (x0 + 3 x1), y1 + error}},
{{1/4 (3 x0 + x1), y1 - error}, {1/4 (x0 + 3 x1), y1 - error}}
}]
}}
]
This function adds error bars to BarChart
. Here is an example using some random data with random errors:
chartData = MapThread[{#1 -> #2} &, {RandomReal[1, 10], RandomReal[0.1, 10]}]
Now plotting it, as per the tutorial:
BarChart[chartData, ChartElementFunction -> errorBar["Rectangle"]]
How can I adjust variable spacing between the bars, e.g. have two groups of five bars without any spacing between them, and then a spacing of, say, 1 between the two groups?