VegaLite throws error on faceting plots

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…

# 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.

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.

# 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"    
) 

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 and place a layer inside a facet.

The correct code:

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
2 Likes