# VegaLite throws error on faceting plots

**URL:** <https://discourse.julialang.org/t/vegalite-throws-error-on-faceting-plots/32396>\
**Category:** Visualization\
**Created:** [December 17, 2019, 6:05pm UTC](https://discourse.julialang.org/t/vegalite-throws-error-on-faceting-plots/32396 "2019-12-17T18:05:08Z")\
**Posts on this page:** 3\
**Page:** 1

<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:** [December 17, 2019, 6:05pm UTC](https://discourse.julialang.org/t/vegalite-throws-error-on-faceting-plots/32396/1 "2019-12-17T18:05:08Z")

</div>

The following code plots data on a single plot. The data is melted data with column names `Symbol[:variable, :value, :time]`. I particularly want lines and points for each dataset… I know I can used `filled=true` but I am also trying to learn Vegalite. The following code works, but it’s all one plot…

```julia
# plot the data using melted data
dfm |> 
@vlplot(
    x={
        :time,
        typ= "quantitative",
        axis={
            title="Time in Weeks"
        }
    },
    y={:value, typ="quantitative", axis={title="Cumulative Cases"}},
    width=400,
    height=400, 
    color="variable:n",    
) + 
@vlplot(
   mark={
        typ="line",
        color="#e6959c",
        size=2
    }
) + 
@vlplot(
    mark={
        typ=:point, 
        filled=true,
        typ="square"
    }
)

```

When I add `column="variable:n"` in the spec, it throws an error. i.e.

```julia
dfm |> 
@vlplot(
    x={
        :time,
        typ= "quantitative",
        axis={
            title="Time in Weeks"
        }
    },
    y={:value, typ="quantitative", axis={title="Cumulative Cases"}},
    width=400,
    height=400, 
    color="variable:n",
    column="variable:n"    
) + 
@vlplot(
   mark={
        typ="line",
        color="#e6959c",
        size=2
    }
) + 
@vlplot(
    mark={
        typ=:point, 
        filled=true,
        typ="square"
    }
)

TypeError: Cannot read property 'push' of undefined
    at C:\Users\affan\.julia\packages\VegaLite\CzoMX\deps\node_modules\vega-lite\build\vega-lite.js:3158:33
    at Array.reduce (<anonymous>)
    at pathGroupingFields (C:\Users\affan\.julia\packages\VegaLite\CzoMX\deps\node_modules\vega-lite\build\vega-lite.js:3101:31)
    at parsePathMark (C:\Users\affan\.julia\packages\VegaLite\CzoMX\deps\node_modules\vega-lite\build\vega-lite.js:16548:25)
    at parseMarkGroups (C:\Users\affan\.julia\packages\VegaLite\CzoMX\deps\node_modules\vega-lite\build\vega-lite.js:16540:20)
    at UnitModel.parseMarkGroup (C:\Users\affan\.julia\packages\VegaLite\CzoMX\deps\node_modules\vega-lite\build\vega-lite.js:16813:35)
    at LayerModel.parseMarkGroup (C:\Users\affan\.julia\packages\VegaLite\CzoMX\deps\node_modules\vega-lite\build\vega-lite.js:16896:23)
    at LayerModel.parse (C:\Users\affan\.julia\packages\VegaLite\CzoMX\deps\node_modules\vega-lite\build\vega-lite.js:13943:18)
    at Object.compile (C:\Users\affan\.julia\packages\VegaLite\CzoMX\deps\node_modules\vega-lite\build\vega-lite.js:17068:19)
    at compile (C:\Users\affan\.julia\packages\VegaLite\CzoMX\src\rendering\vl2vg.js:18:27)
SyntaxError: Unexpected end of JSON input
    at JSON.parse (<anonymous>)
    at C:\Users\affan\.julia\packages\VegaLite\CzoMX\deps\node_modules\vega-cli\src\render.js:61:31
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
TypeError: Cannot read property 'push' of undefined
    at C:\Users\affan\.julia\packages\VegaLite\CzoMX\deps\node_modules\vega-lite\build\vega-lite.js:3158:33
    at Array.reduce (<anonymous>)
    at pathGroupingFields (C:\Users\affan\.julia\packages\VegaLite\CzoMX\deps\node_modules\vega-lite\build\vega-lite.js:3101:31)
    at parsePathMark (C:\Users\affan\.julia\packages\VegaLite\CzoMX\deps\node_modules\vega-lite\build\vega-lite.js:16548:25)
    at parseMarkGroups (C:\Users\affan\.julia\packages\VegaLite\CzoMX\deps\node_modules\vega-lite\build\vega-lite.js:16540:20)
    at UnitModel.parseMarkGroup (C:\Users\affan\.julia\packages\VegaLite\CzoMX\deps\node_modules\vega-lite\build\vega-lite.js:16813:35)
    at LayerModel.parseMarkGroup (C:\Users\affan\.julia\packages\VegaLite\CzoMX\deps\node_modules\vega-lite\build\vega-lite.js:16896:23)
    at LayerModel.parse (C:\Users\affan\.julia\packages\VegaLite\CzoMX\deps\node_modules\vega-lite\build\vega-lite.js:13943:18)
    at Object.compile (C:\Users\affan\.julia\packages\VegaLite\CzoMX\deps\node_modules\vega-lite\build\vega-lite.js:17068:19)
    at compile (C:\Users\affan\.julia\packages\VegaLite\CzoMX\src\rendering\vl2vg.js:18:27)
[166]:

Javascript Error: Bug: Channel column unimplemented for line mark

SyntaxError: Unexpected end of JSON input
    at JSON.parse (<anonymous>)
    at C:\Users\affan\.julia\packages\VegaLite\CzoMX\deps\node_modules\vega-cli\src\render.js:61:31
    at processTicksAndRejections (internal/process/task_queues.js:93:5)

```

If I get rid of the extra `@vlplot` specs, it works… i.e.

```julia
# plot the data using melted data
dfm |> 
@vlplot(
    :line,
    x={
        :time,
        typ= "quantitative",
        axis={
            title="Time in Weeks"
        }
    },
    y={:value, typ="quantitative", axis={title="Cumulative Cases"}},
    width=400,
    height=400, 
    color="variable:n",
    column="variable:n"    
) 

```

---

<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:** [December 17, 2019, 6:53pm UTC](https://discourse.julialang.org/t/vegalite-throws-error-on-faceting-plots/32396/2 "2019-12-17T18:53:54Z")

</div>

Actually I don’t think this is a `Vegalite` issue… but more of how the spec is formed. From the docs:

> **Note** : Specifications inside `layer` cannot use `row` and `column` channels as layering facet specifications is not allowed. Instead, use the [facet operator](https://vega.github.io/vega-lite/docs/facet.html) and place a layer inside a facet.

---

<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:** [December 17, 2019, 7:30pm UTC](https://discourse.julialang.org/t/vegalite-throws-error-on-faceting-plots/32396/3 "2019-12-17T19:30:02Z")

</div>

The correct code:

```julia
spec = dfm |> 
@vlplot(facet={column={field="variable", typ="nominal"}}) +
(
    @vlplot(
        x={:time,
            typ= "quantitative",
            axis={
                title="Time in Weeks"
            }
        },
        y={:value, typ="quantitative", axis={title="Cumulative Cases"}},
        width=400,
        height=400,
      color="variable:n") +
    @vlplot(
        mark="line"
    ) + 
    @vlplot(
        mark="point"
    )
)
save("testspec.vegalite", spec)
spec

```
