# Overlaying multiple plots in VegaLite

**URL:** <https://discourse.julialang.org/t/overlaying-multiple-plots-in-vegalite/25945>\
**Category:** General Usage\
**Tags:** plotting\
**Created:** [July 2, 2019, 10:30pm UTC](https://discourse.julialang.org/t/overlaying-multiple-plots-in-vegalite/25945 "2019-07-02T22:30:26Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![yanivab](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yanivab/32/9164_2.png) [@yanivab](https://discourse.julialang.org/u/yanivab)\
**Post date:** [July 2, 2019, 10:30pm UTC](https://discourse.julialang.org/t/overlaying-multiple-plots-in-vegalite/25945/1 "2019-07-02T22:30:27Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![davidanthoff](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/davidanthoff/32/223493_2.png) [@davidanthoff](https://discourse.julialang.org/u/davidanthoff)\
**Post date:** [July 3, 2019, 3:26pm UTC](https://discourse.julialang.org/t/overlaying-multiple-plots-in-vegalite/25945/2 "2019-07-03T15:26:11Z")

</div>

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:

```julia
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.

---

<div class="post-metadata">

**Author:** ![yanivab](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yanivab/32/9164_2.png) [@yanivab](https://discourse.julialang.org/u/yanivab)\
**Post date:** [July 3, 2019, 3:40pm UTC](https://discourse.julialang.org/t/overlaying-multiple-plots-in-vegalite/25945/3 "2019-07-03T15:40:03Z")

</div>

Thanks for your answer!

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

Will open the issue.

---

<div class="post-metadata">

**Author:** ![davidanthoff](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/davidanthoff/32/223493_2.png) [@davidanthoff](https://discourse.julialang.org/u/davidanthoff)\
**Post date:** [July 3, 2019, 3:51pm UTC](https://discourse.julialang.org/t/overlaying-multiple-plots-in-vegalite/25945/4 "2019-07-03T15:51:38Z")

</div>

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.
