How to make Geom.errorbar work with Geom.subplot_grid in Gadfly.jl

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

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?

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. And may be eventually fixed by https://github.com/GiovineItalia/Gadfly.jl/pull/1520 (which I hope to return to some day!)

1 Like

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

image