A trellis style set of barcharts with facets

72 views
Skip to first unread message

sg...@mozilla.com

unread,
Oct 17, 2018, 6:22:44 PM10/17/18
to vega-js
Hello,

I would like to display trellis style of barcharts. Each panel has a barchart of some measure M for different branches faceted by countries. Each panel in my trellis display
is a year x season. I have 3 years (three rows) and 3 seasons (3 columns) and within each the barchart described above.
In latttice (R) it would be like

barchart( M ~ countries| year*season,groups=branch, data=...)

In this example https://vega.github.io/vega-lite/docs/bar.html#grouped-bar-chart Facets are used for the countries.

However the documentation for Layers( https://vega.github.io/vega-lite/docs/layer.html) says my layers can't have Facets

"Specifications inside layer cannot use row and column channels as layering facet specifications is not allowed."

So how would i go about creating this display?
Cheers
Saptarshi

Dominik Moritz

unread,
Oct 18, 2018, 9:25:38 AM10/18/18
to sg...@mozilla.com, vega-js
You can put layers into facets instead of facets into layers. To do this, you have to use the more verbose format. I'll update the docs to add a hint about this. 

pasted1

{
"data": {
"url": "data/cars.json"
},
"facet": {
"row": {
"field": "Origin",
"type": "nominal"
}
},
"spec": {
"layer": [
{
"mark": "bar",
"encoding": {
"x": {
"bin": {
"maxbins": 15
},
"field": "Horsepower",
"type": "quantitative"
},
"y": {
"aggregate": "count",
"type": "quantitative"
}
}
},
{
"mark": "line",
"encoding": {
"x": {
"bin": {
"maxbins": 15
},
"field": "Horsepower",
"type": "quantitative"
},
"y": {
"aggregate": "count",
"type": "quantitative"
},
"color": {
"value": "red"
}
}
}
]
}
}

--
You received this message because you are subscribed to the Google Groups "vega-js" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vega-js+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages