vega-lite
vega-lite copied to clipboard
Quantitative area chart does not stack
I would expect this chart to stack. It does stack when I switch the x encoding to be ordinal.
{
"$schema": "https://vega.github.io/schema/vega-lite/v5.json",
"data": {
"values": [
{"a": 0, "b": 28, "c": "A"},
{"a": 1, "b": 55, "c": "A"},
{"a": 0, "b": 28, "c": "B"},
{"a": 1, "b": 55, "c": "B"}
]
},
"mark": "area",
"encoding": {
"x": {"field": "a", "type": "quantitative"},
"y": {"field": "b", "type": "quantitative"},
"color": {"field": "c", "type": "nominal"}
}
}
Actually, we can enable stacking manually. The question is, why
{
"$schema": "https://vega.github.io/schema/vega-lite/v5.json",
"data": {
"values": [
{"a": 0, "b": 28, "c": "A"},
{"a": 1, "b": 55, "c": "A"},
{"a": 0, "b": 28, "c": "B"},
{"a": 1, "b": 55, "c": "B"}
]
},
"mark": "area",
"encoding": {
"x": {"field": "a", "type": "quantitative"},
"y": {"field": "b", "type": "quantitative", "stack": true},
"color": {"field": "c", "type": "nominal"}
}
}
Default stacking was enabled in https://github.com/vega/vega-lite/issues/6864.
This also seems to apply to other charts like bar charts - the bars don't stack if the x
type is 'quantitative' but will stack if it's changed to 'nominal' or such.