# VegaLite: Facet plot with errorband

**URL:** <https://discourse.julialang.org/t/vegalite-facet-plot-with-errorband/35903>\
**Category:** Visualization\
**Tags:** question\
**Created:** [March 12, 2020, 10:20pm UTC](https://discourse.julialang.org/t/vegalite-facet-plot-with-errorband/35903 "2020-03-12T22:20:36Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![hellemo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hellemo/32/324_2.png) [@hellemo](https://discourse.julialang.org/u/hellemo)\
**Post date:** [March 12, 2020, 10:20pm UTC](https://discourse.julialang.org/t/vegalite-facet-plot-with-errorband/35903/1 "2020-03-12T22:20:36Z")

</div>

Does VegaLite not support faceting of plots with errorbands? I’m struggling to make this work:

```julia
using VegaLite, DataFrames

function generatedata()
    df = DataFrame()
    K = 10
    L = 10
    Cat1 = [:A,:B]
    Cat2 = [:X,:Y]
    for i in Cat1, j in Cat2
        tmp = DataFrame()
        tmp.Cat1 = [i for _ in 1:K*L]
        tmp.Cat2 = [j for _ in 1:K*L]
        tmp.Week = [rem(w,K) for w in 1:K*L]
        df = vcat(df,tmp)
    end
    df.Id = [i for i in 1:size(df,1)]
    df.Value = rand(size(df,1))
    df[df.Cat1.==:A,:Value] .+=1
    df[df.Cat2.==:X,:Value] .-=2
    return df
end

df = generatedata()

# Works (Error band + color + mean)
df |> @vlplot(x=:Week,color=:Cat2) + @vlplot(mark={:errorband, extent=:ci},y=:Value) + @vlplot(:line,y="mean(Value)")
# Facet version of this does not work:
df |> @vlplot(x=:Week,color=:Cat2,column=:Cat1) + @vlplot(mark={:errorband, extent=:ci},y=:Value) + @vlplot(:line,y="mean(Value)")
# Works (simple line version)
df |> @vlplot(:line,x=:Week,color=:Cat1,column=:Cat2,y="mean(Value)")

```

![image](https://global.discourse-cdn.com/julialang/original/3X/1/7/170266ea19f37cfe6a441769bb12088689b2a025.png)

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

---

<div class="post-metadata">

**Author:** ![oheil](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oheil/32/220745_2.png) [@oheil](https://discourse.julialang.org/u/oheil)\
**Post date:** [March 13, 2020, 9:46am UTC](https://discourse.julialang.org/t/vegalite-facet-plot-with-errorband/35903/2 "2020-03-13T09:46:29Z")

</div>

We had a similar question here

> [@VegaLite: facet plot with running average layer](https://discourse.julialang.org/t/vegalite-facet-plot-with-running-average-layer/35463):
>
> I have a dataset with continuous values and would like to plot those values together with their running averages in a layered plot. Works well in this simple case: using Random, DataFrames, Queryverse Random.seed!(1234) df = DataFrame(index=1:100, value=rand(100)) df |\> @vlplot(transform=[{frame= [-15, 15], window=[{op=:mean, field=:value, as=:avg\_value}]}]) + @vlplot( mark={:line, strokeWidth=2, opacity=0.5}, x="index:q", y="value:q" ) + @vlplot( mark={:line, strokeWidth=3}, …

The solution wasn’t obvious so maybe it is similar here. Could you try for yourself? I could perhaps look later into details.

---

<div class="post-metadata">

**Author:** ![jtackm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jtackm/32/4784_2.png) [@jtackm](https://discourse.julialang.org/u/jtackm)\
**Post date:** [March 13, 2020, 12:40pm UTC](https://discourse.julialang.org/t/vegalite-facet-plot-with-errorband/35903/3 "2020-03-13T12:40:49Z")

</div>

This works for me (VegaLite 1.0.0):

```julia
df |>
@vlplot(
    facet={column={field="Cat1", type="nominal"}}
) + 
(
    @vlplot(x="Week:q",color="Cat2:n") + 
    @vlplot(mark={:errorband, extent=:ci},y="Value:q") + 
    @vlplot(:line,y="mean(Value)")
)

```

![image](https://global.discourse-cdn.com/julialang/original/3X/2/8/286774eb0c9611ca9cd139590ad1a2553ec645b4.png)

---

<div class="post-metadata">

**Author:** ![hellemo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hellemo/32/324_2.png) [@hellemo](https://discourse.julialang.org/u/hellemo)\
**Post date:** [March 13, 2020, 2:48pm UTC](https://discourse.julialang.org/t/vegalite-facet-plot-with-errorband/35903/4 "2020-03-13T14:48:15Z")

</div>

> [@jtackm](#):
>
> df |\> @vlplot( facet={column={field=“Cat1”, type=“nominal”}} ) + ( @vlplot(x=“Week:q”,color=“Cat2:n”) + @vlplot(mark={:errorband, extent=:ci},y=“Value:q”) + @vlplot(:line,y=“mean(Value)”) )

Brilliant! That works for me! Thanks a lot @jtackm! I also found the answer that @oheil mentioned, but wasn’t able to map it to my case last night. Thanks both of you!

---

<div class="post-metadata">

**Author:** ![affans](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/affans/32/11911_2.png) [@affans](https://discourse.julialang.org/u/affans)\
**Post date:** [March 13, 2020, 4:55pm UTC](https://discourse.julialang.org/t/vegalite-facet-plot-with-errorband/35903/5 "2020-03-13T16:55:13Z")

</div>

On faceting, you can see my problem and solution which may be applicable to you.

[VegaLite throws error on faceting plots](https://discourse.julialang.org/t/vegalite-throws-error-on-faceting-plots/32396)

Although I am not sure if the behaviour has changed with the newest release.
