Skip to content

Instantly share code, notes, and snippets.

@domoritz
Last active June 17, 2020 05:26
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 domoritz/576c9880271900bdc15cc79851ebac41 to your computer and use it in GitHub Desktop.
Save domoritz/576c9880271900bdc15cc79851ebac41 to your computer and use it in GitHub Desktop.
NYT Covid 19 Data
{
"$schema": "https://vega.github.io/schema/vega-lite/v4.json",
"data": {
"url": "https://raw.githubusercontent.com/nytimes/covid-19-data/master/us.csv",
"format": {"parse": {"deaths": "number"}}
},
"transform": [
{
"window": [
{"field": "deaths", "as": "previous_deaths", "op": "lag", "param": 1},
{"field": "cases", "as": "previous_cases", "op": "lag", "param": 1}
]
},
{"calculate": "datum.deaths - datum.previous_deaths", "as": "deaths"},
{"calculate": "datum.cases - datum.previous_cases", "as": "cases"},
{"filter": {"field": "date", "gt": {"month": 3, "year": 2020}}}
],
"title": {
"text": "New reported deaths by day in the United States",
"align": "right",
"offset": 10
},
"view": {"stroke": null},
"width": 500,
"layer": [
{
"mark": {"type": "bar", "color": "#ccc"},
"encoding": {
"x": {
"field": "date",
"type": "temporal",
"timeUnit": "yearmonthdate",
"axis": {"grid": false, "title": null, "tickCount": 3, "format": "%B"}
},
"y": {
"field": "deaths",
"type": "quantitative",
"axis": {"tickCount": 3, "domain": false, "ticks": false, "title": null}
},
"tooltip": [
{"field": "date", "type": "temporal"},
{"field": "cases", "type": "quantitative", "title": "Cases"},
{"field": "deaths", "type": "quantitative", "title": "Deaths"}
]
}
},
{
"transform": [
{
"window": [{"field": "deaths", "op": "mean", "as": "deaths"}],
"frame": [-7, 0]
}
],
"encoding": {
"x": {"field": "date", "type": "temporal", "timeUnit": "yearmonthdate"},
"y": {"field": "deaths", "type": "quantitative"}
},
"mark": {"type": "line", "color": "#666"}
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment