Skip to content

Instantly share code, notes, and snippets.

@shreshthmohan
Last active August 15, 2022 11:55
Show Gist options
  • Save shreshthmohan/27bbb653b993fe8a5569ddf924aed976 to your computer and use it in GitHub Desktop.
Save shreshthmohan/27bbb653b993fe8a5569ddf924aed976 to your computer and use it in GitHub Desktop.
{
"width": 60,
"height": 30,
"data": {
"name": "source",
"url": "https://gist.githubusercontent.com/shreshthmohan/b23aa75458a42416464cfbb963851897/raw/028fcaa47c297f2bf6aa7727b0549450af12c313/drought.tsv",
"format": {
"type": "tsv",
"parse": {
"0": "number",
"1": "number",
"2": "number",
"3": "number",
"4": "number",
"5": "number",
"6": "number"
}
}
},
"transform": [
{
"calculate": "datum['0']+datum['1']+datum['2']+datum['3']+datum['4']+datum['5']+datum['6']",
"as": "s1"
},
{ "fold": ["0", "1", "2", "3", "4", "5", "6"], "as": ["fkey", "fvalue"] }
],
"mark": { "type": "bar", "tooltip": { "content": "data" } },
"encoding": {
"row": { "field": "decade", "type": "nominal" },
"column": { "field": "year_in_decade", "type": "nominal" },
"x": { "field": "month", "type": "nominal", "scale": { "rangeStep": 12 } },
"y": { "field": "fvalue", "type": "quantitative", "scale": {} },
"color": {
"field": "fkey",
"scale": { "scheme": "redyellowgreen" },
"legend": {
"labelExpr": " datum.label === '0' ? 'Extreme drought' : datum.label === '1' ? 'Severe drought' : datum.label === '2' ? 'Moderate drought' : datum.label === '3' ? 'Average' : datum.label === '4' ? 'Moderately moist' : datum.label === '5' ? 'Very moist' : datum.label === '6' ? 'Extremely moist' : ''"
}
},
"tooltip": [
{
"field": "0",
"type": "quantitative",
"format": "~%",
"title": "Extreme drought"
},
{
"field": "1",
"type": "quantitative",
"format": "~%",
"title": "Severe drought"
},
{
"field": "2",
"type": "quantitative",
"format": "~%",
"title": "Moderate drought"
},
{
"field": "3",
"type": "quantitative",
"format": "~%",
"title": "Average"
},
{
"field": "4",
"type": "quantitative",
"format": "~%",
"title": "Moderately moist"
},
{
"field": "5",
"type": "quantitative",
"format": "~%",
"title": "Very moist"
},
{
"field": "6",
"type": "quantitative",
"format": "~%",
"title": "Extremely moist"
}
]
},
"config": {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment