# Makie: Errorbars for grouped bar graphs

**URL:** <https://discourse.julialang.org/t/makie-errorbars-for-grouped-bar-graphs/62361>\
**Category:** General Usage\
**Tags:** question, makie\
**Created:** [June 3, 2021, 9:51pm UTC](https://discourse.julialang.org/t/makie-errorbars-for-grouped-bar-graphs/62361 "2021-06-03T21:51:07Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![hendri54](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hendri54/32/9621_2.png) [@hendri54](https://discourse.julialang.org/u/hendri54)\
**Post date:** [June 3, 2021, 9:51pm UTC](https://discourse.julialang.org/t/makie-errorbars-for-grouped-bar-graphs/62361/1 "2021-06-03T21:51:07Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)\
**Post date:** [June 4, 2021, 7:12am UTC](https://discourse.julialang.org/t/makie-errorbars-for-grouped-bar-graphs/62361/2 "2021-06-04T07:12:25Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![piever](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/piever/32/1815_2.png) [@piever](https://discourse.julialang.org/u/piever)\
**Post date:** [June 4, 2021, 8:30am UTC](https://discourse.julialang.org/t/makie-errorbars-for-grouped-bar-graphs/62361/3 "2021-06-04T08:30:23Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![hendri54](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hendri54/32/9621_2.png) [@hendri54](https://discourse.julialang.org/u/hendri54)\
**Post date:** [June 4, 2021, 11:38am UTC](https://discourse.julialang.org/t/makie-errorbars-for-grouped-bar-graphs/62361/4 "2021-06-04T11:38:07Z")

</div>

That would be great.

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)\
**Post date:** [June 4, 2021, 11:49am UTC](https://discourse.julialang.org/t/makie-errorbars-for-grouped-bar-graphs/62361/5 "2021-06-04T11:49:34Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![piever](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/piever/32/1815_2.png) [@piever](https://discourse.julialang.org/u/piever)\
**Post date:** [June 4, 2021, 12:57pm UTC](https://discourse.julialang.org/t/makie-errorbars-for-grouped-bar-graphs/62361/6 "2021-06-04T12:57:14Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![tbenst](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tbenst/32/3029_2.png) [@tbenst](https://discourse.julialang.org/u/tbenst)\
**Post date:** [September 9, 2021, 10:33pm UTC](https://discourse.julialang.org/t/makie-errorbars-for-grouped-bar-graphs/62361/7 "2021-09-09T22:33:06Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![sijo](https://avatars.discourse-cdn.com/v4/letter/s/da6949/32.png) [@sijo](https://discourse.julialang.org/u/sijo)\
**Post date:** [January 4, 2022, 12:01pm UTC](https://discourse.julialang.org/t/makie-errorbars-for-grouped-bar-graphs/62361/8 "2022-01-04T12:01:15Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Aesth\_Estheticism](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aesth_estheticism/32/36584_2.png) [@Aesth\_Estheticism](https://discourse.julialang.org/u/Aesth_Estheticism)\
**Post date:** [July 30, 2022, 1:39pm UTC](https://discourse.julialang.org/t/makie-errorbars-for-grouped-bar-graphs/62361/9 "2022-07-30T13:39:18Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![hendri54](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hendri54/32/9621_2.png) [@hendri54](https://discourse.julialang.org/u/hendri54)\
**Post date:** [July 30, 2022, 7:45pm UTC](https://discourse.julialang.org/t/makie-errorbars-for-grouped-bar-graphs/62361/10 "2022-07-30T19:45:59Z")

</div>

I still use `crossbar` and it works fine for me

```julia
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):

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

```

---

<div class="post-metadata">

**Author:** ![Aesth\_Estheticism](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aesth_estheticism/32/36584_2.png) [@Aesth\_Estheticism](https://discourse.julialang.org/u/Aesth_Estheticism)\
**Post date:** [July 31, 2022, 2:55am UTC](https://discourse.julialang.org/t/makie-errorbars-for-grouped-bar-graphs/62361/11 "2022-07-31T02:55:54Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![filchristou](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/filchristou/32/26760_2.png) [@filchristou](https://discourse.julialang.org/u/filchristou)\
**Post date:** [October 16, 2023, 5:00pm UTC](https://discourse.julialang.org/t/makie-errorbars-for-grouped-bar-graphs/62361/12 "2023-10-16T17:00:16Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Geoffrey](https://avatars.discourse-cdn.com/v4/letter/g/bc8723/32.png) [@Geoffrey](https://discourse.julialang.org/u/Geoffrey)\
**Post date:** [November 11, 2023, 12:43pm UTC](https://discourse.julialang.org/t/makie-errorbars-for-grouped-bar-graphs/62361/13 "2023-11-11T12:43:36Z")

</div>

I did open an [issue](https://github.com/MakieOrg/Makie.jl/issues/3300) 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.

---

<div class="post-metadata">

**Author:** ![filchristou](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/filchristou/32/26760_2.png) [@filchristou](https://discourse.julialang.org/u/filchristou)\
**Post date:** [January 4, 2024, 9:21am UTC](https://discourse.julialang.org/t/makie-errorbars-for-grouped-bar-graphs/62361/14 "2024-01-04T09:21:29Z")

</div>

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