Created
March 26, 2018 17:53
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "$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