Makie: Errorbars for grouped bar graphs

How can I add errorbars to a grouped bar plot in Makie.jl?

One option is to use crossbar, but this generates a bar graph indicating the error range, not the usual line + whisker.

You mean the errorbars function doesn’t work because it doesn’t include the grouping?

We should probably add dodge to the error bar recipe, so that one just has to pass in the same dodge variable than in the bar plot.

That would be great.

Does it make more sense to make a barplot-with-errorbars recipe instead? There might be other things that you’d want to dodge, but it seems weird to me to add it to every basic recipe. If I think about errorbars, I don’t think about dodging. Only in conjunction with barplots.

That also makes sense. It seems like dodged errorbars only really make sense for dodged barplot and in a dodged violin plot (to have a vertical line in the middle marking some quantiles), but again, that could just be part of the violin recipe.

On a related not, I’m curious whether we can find a parametric approach to encode the “estimator + error” plots. Something along the lines of

  • plot(Errorplot{BarPlot, ErrorBars}, x, ys, ylower, yupper)
  • plot(Errorplot{Scatter, ErrorBars}, x, ys, ylower, yupper)
  • plot(Errorplot{Scatter, Band}, x, ys, ylower, yupper)
  • plot(Errorplot{Lines, ErrorBars}, x, ys, ylower, yupper)
  • plot(Errorplot{Lines, Band}, x, ys, ylower, yupper)

where ErrorPlot would be the parametric recipe, hopefully with a better name. In this case, the BarPlot case would have a special method that takes dodging into account.

This would also help with AlgebraOfGraphics, because then analyses that return estimate plus error would only need return to return one layer with this composite recipe.


I just got hit by this when trying to compose bar plot with dodge and errorbar with dodge. Is there a workaround other than crossbar?

Also just hit by this. @tbenst did you find a workaround? (also with crossbar I can’t seem to get the horizontal position right).

I’m stuck in this too. Hasn’t Makie solved the problem yet?

I still use crossbar and it works fine for me

ax = <make an Axis>
dataM = <data matrix>
yerror = <matrix with width of error bands>
nr, nc = size(dataM);
xV = repeat(1 : nr; outer = (nc,));
grps = groups_from_rows(nr, nc);
barplot!(ax, xV, vec(dataM);  dodge = grps);
crossbar!(xV, vec(dataM), vec(dataM) .- vec(yerror), vec(dataM) .+ vec(yerror); 
        dodge = grps, color = (:gray50, 0.35))

where groups_from_rows is a function that makes the vector of group indicators (each row of dataM is a group):

groups_from_rows(nr, nc) = repeat(1 : nc; inner = (nr,));

That’s fine. Thanks for your reply, hope Makie package could fix the bug for barplot!.

did anybody find a way to at least make the crossbar smaller in width, but still overlaying the previous barplot ? No matter how I change the width and the gap I cannot achieve the overlay with the previous barplot but with thinner bars.

I did open an issue on Makie.jl for this feature. In the mean time you could use the trick that I describe in this issue to produce the dodge barplot with errorbar.

1 Like

loved that. Thanks for taking the time and writing the workaround; works like a charm. I totally agree this should be in-house supported.