# How to make Geom.errorbar work with Geom.subplot\_grid in Gadfly.jl

**URL:** <https://discourse.julialang.org/t/how-to-make-geom-errorbar-work-with-geom-subplot-grid-in-gadfly-jl/80158>\
**Category:** Visualization\
**Tags:** gadfly\
**Created:** [April 27, 2022, 5:35pm UTC](https://discourse.julialang.org/t/how-to-make-geom-errorbar-work-with-geom-subplot-grid-in-gadfly-jl/80158 "2022-04-27T17:35:05Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![rkmalaiya](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rkmalaiya/32/31236_2.png) [@rkmalaiya](https://discourse.julialang.org/u/rkmalaiya)\
**Post date:** [April 27, 2022, 5:35pm UTC](https://discourse.julialang.org/t/how-to-make-geom-errorbar-work-with-geom-subplot-grid-in-gadfly-jl/80158/1 "2022-04-27T17:35:05Z")

</div>

Hello Everyone,

I am trying to make bar plot with error bars in a plot grid. But I am getting following error. Please advise what I may be doing wrong.

**Fake Data**

> v = rand(8)  
> df\_plot = DataFrame(  
> model = repeat([“M1”,“M2”, “M3”, “M4”],inner=2),  
> sample = repeat([“1”,“2”], outer=4),  
> value=v,  
> v\_min = v.-0.1,  
> v\_max = v.+0.1,  
> )

**Plot without using subplot\_grid**  
I am putting this plot here to show how the errorbars look in my “fake” data  
_Code_

> p = Gadfly.plot(  
> df\_plot,  
> x=:sample,  
> y=:value,  
> color=:model,  
> ymin=:v\_min,  
> ymax=:v\_max,  
> Geom.bar(position = :dodge), Geom.errorbar, Stat.dodge,  
> Scale.x\_discrete  
> )  
> draw(SVG(),p)  
> ![image](https://global.discourse-cdn.com/julialang/original/3X/3/8/384876cd66d5b42837c84fe9aeda8779e1e66379.png)

**Using subplot\_grid.** _Gives error_  
_Code_

> p = Gadfly.plot(  
> df\_plot,  
> x=:sample,  
> y=:value,  
> xgroup=:model,  
> ymin=:v\_min,  
> ymax=:v\_max,  
> Geom.subplot\_grid(Geom.bar(position = :dodge), Geom.errorbar, Stat.dodge),  
> Scale.x\_discrete  
> )  
> draw(SVG(),p)

_Error_

> The following aesthetics are required by Geom.errorbar to be of equal length: y, xmin, xmax
> 
> Stacktrace:  
> [1] error(::String, ::String, ::String, ::String, ::String)  
> @ Base .\error.jl:42  
> [2] assert\_aesthetics\_equal\_length(::String, ::Gadfly.Aesthetics, ::Symbol, ::Vararg{Symbol})

I am not sure if I need to specify xmin, xmax. And even if I need to specify, what should I provide here?

---

<div class="post-metadata">

**Author:** ![Mattriks](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mattriks/32/351_2.png) [@Mattriks](https://discourse.julialang.org/u/Mattriks)\
**Post date:** [April 28, 2022, 12:10am UTC](https://discourse.julialang.org/t/how-to-make-geom-errorbar-work-with-geom-subplot-grid-in-gadfly-jl/80158/2 "2022-04-28T00:10:25Z")

</div>

The solution here is to use `Geom.yerrorbar` rather than the more general `Geom.errorbar`. The issue is that `Geom.errorbar` (when used with `Geom.subplot_grid`) is trying to inherit {`:xmin`, `:xmax`, `:ymin`, `:ymax`} from the plot. Might be related to [https://github.com/GiovineItalia/Gadfly.jl/issues/1516](https://github.com/GiovineItalia/Gadfly.jl/issues/1516). And may be eventually fixed by [https://github.com/GiovineItalia/Gadfly.jl/pull/1520](https://github.com/GiovineItalia/Gadfly.jl/pull/1520) (which I hope to return to some day!)

---

<div class="post-metadata">

**Author:** ![rkmalaiya](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rkmalaiya/32/31236_2.png) [@rkmalaiya](https://discourse.julialang.org/u/rkmalaiya)\
**Post date:** [April 28, 2022, 5:38pm UTC](https://discourse.julialang.org/t/how-to-make-geom-errorbar-work-with-geom-subplot-grid-in-gadfly-jl/80158/3 "2022-04-28T17:38:08Z")

</div>

> [@Mattriks](#):
>
> Geom.yerrorbar

Thanks a lot for the solution. I am now able to make the plot

![image](https://global.discourse-cdn.com/julialang/original/3X/4/4/447f2119e56ba02267e6844482b442fdd921291a.png)
