Overlaying multiple plots in VegaLite

I’m trying to plot two errorbands on top of each other (one for a 50% CI, one for a 80% CI). The lower and upperbounds of each errorband are saved as four columns in a dataframe, together with the x axis variable.

As a minimal example, I have this code:

DataFrame(q = 1:20, lb50 = 2, ub50 = 3, lb80 = 1, ub80 = 4) |> @vlplot() +
@vlplot(mark = {:errorband, color = :blue}, y = :lb80, y2= :ub80, x = :q) +
@vlplot(mark = {:errorband, color = :green}, y = :lb50, y2= :ub50, x = :q)
I’m getting an error:
Error: Invalid field type “undefined”

Any ideas about how to achieve this?
thanks!

1 Like

It seems you need to specify the type of the data in each encoding manual, i.e. specify that this is all quant data like this:

DataFrame(q = 1:20, lb50 = 2, ub50 = 3, lb80 = 1, ub80 = 4) |> @vlplot() +
@vlplot(mark = {:errorband, color = :blue}, y = "lb80:q", y2= "ub80:q", x = "q:q") +
@vlplot(mark = {:errorband, color = :green}, y = "lb50:q", y2= "ub50:q", x = "q:q")

We normally try to infer the data type automatically and augment the spec accordingly, but that logic seems to fail with these composite figures. Could you maybe open an issue over in the github repo for this? It should be possible to make this just work with the code you tried.

1 Like

Thanks for your answer!

At the very least, the error message has to be more informative.

Will open the issue.

I don’t think I can do anything about the error message, unfortunately… I comes from the underlying vega-lite javascript library, which is out of my control.