Normalized (Percentage) Stacked Bar Chart
View this example in the online editor
Vega-Lite JSON Specification
{
"$schema": "https://vega.github.io/schema/vega-lite/v4.json",
"data": { "url": "data/population.json"},
"transform": [
{"filter": "datum.year == 2000"},
{"calculate": "datum.sex == 2 ? 'Female' : 'Male'", "as": "gender"}
],
"mark": "bar",
"width": {"step": 17},
"encoding": {
"y": {
"aggregate": "sum", "field": "people",
"title": "population",
"stack": "normalize"
},
"x": {"field": "age"},
"color": {
"field": "gender",
"scale": {"range": ["#675193", "#ca8861"]}
}
}
}