Skip to content

Instantly share code, notes, and snippets.

@simonw
Created March 26, 2018 17:53
Show Gist options
  • Select an option

  • Save simonw/48d65e8b84158f9dd509009ff8066841 to your computer and use it in GitHub Desktop.

Select an option

Save simonw/48d65e8b84158f9dd509009ff8066841 to your computer and use it in GitHub Desktop.
Population by birth gender over time - based on example from https://vega.github.io/vega-lite/docs/stack.html#normalized
{
"$schema": "https://vega.github.io/schema/vega-lite/v2.json",
"vconcat": [
{
"width": 600,
"height": 300,
"mark": "bar",
"data": {
"url": "data/population.json",
"format": {
"type": "json"
}
},
"transform": [
{
"filter": "datum.year == 2000"
},
{
"calculate": "datum.sex == 2 ? 'Female' : 'Male'",
"as": "gender"
}
],
"encoding": {
"y": {
"aggregate": "sum",
"field": "people",
"type": "quantitative",
"axis": {
"title": "population"
}
},
"x": {
"field": "age",
"type": "ordinal",
"scale": {
"rangeStep": 17
}
},
"color": {
"field": "gender",
"type": "nominal",
"scale": {
"range": [
"#EA98D2",
"#659CCA"
]
}
}
}
},
{
"width": 600,
"height": 300,
"mark": "bar",
"data": {
"url": "data/population.json",
"format": {
"type": "json"
}
},
"transform": [
{
"filter": "datum.year == 2000"
},
{
"calculate": "datum.sex == 2 ? 'Female' : 'Male'",
"as": "gender"
}
],
"encoding": {
"y": {
"aggregate": "sum",
"field": "people",
"type": "quantitative",
"axis": {
"title": "population"
},
"stack": "normalize"
},
"x": {
"field": "age",
"type": "ordinal",
"scale": {
"rangeStep": 17
}
},
"color": {
"field": "gender",
"type": "nominal",
"scale": {
"range": [
"#EA98D2",
"#659CCA"
]
}
}
}
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment