Skip to content

Instantly share code, notes, and snippets.

@brew
Created October 5, 2017 10:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brew/ea1da47c90143591a9774fd8cd0e5c81 to your computer and use it in GitHub Desktop.
Save brew/ea1da47c90143591a9774fd8cd0e5c81 to your computer and use it in GitHub Desktop.
Vega view for a visualisation of uk.gov petition data
{
"width": 800,
"height": 200,
"data": [
{
"name": "stocks",
"url": "https://gist.githubusercontent.com/brew/a071efd8fb3dcd28854630d5b8d9ea95/raw/a9d9f9bdfa3c26f960967f0d7897f358106cf3c2/uk-gov-petitions.csv",
"format": {
"type": "csv",
"parse": {"starting": "date:'%Y-%m-%d %H:%M:%S'"}
},
"transform": [
{
"type": "filter",
"test": "datum[\"department\"] == \"Ministry of Defence\""
},
{
"type": "formula",
"field": "starting_day",
"expr": "datetime(year(datum[\"starting\"]), month(datum[\"starting\"]), 2, 0, 0, 0, 0)"
},
{
"type": "aggregate",
"groupby": ["starting_day","department"],
"summarize": [
{
"field": "*",
"ops": ["count"],
"as": ["dept_count"]
}
]
}
]
}
],
"scales": [
{
"name": "x",
"type": "time",
"range": "width",
"domain": {"data": "stocks","field": "starting_day"},
"nice": "month"
},
{
"name": "x2",
"type": "ordinal",
"range": "width",
"domain": {"data": "stocks","field": "starting_day"}
},
{
"name": "y",
"type": "linear",
"range": "height",
"nice": true,
"domain": {"data": "stocks","field": "dept_count"}
},
{
"name": "color",
"type": "ordinal",
"domain": {"data": "stocks","field": "department"},
"range": "category10"
}
],
"axes": [{"type": "x","scale": "x"},{"type": "y","scale": "y"}],
"marks": [
{
"type": "group",
"from": {
"data": "stocks",
"transform": [{"type": "facet","groupby": ["department"]}]
},
"marks": [
{
"type": "rect",
"properties": {
"enter": {
"x": {"scale": "x","field": "starting_day"},
"y": {"scale": "y","field": "dept_count"},
"y2": {"scale": "y","value": 0},
"fill": {"scale": "color","field": "department"},
"width": {"band": true, "scale": "x2", "offset": -1}
}
}
}
]
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment