Last active
April 29, 2020 21:21
-
-
Save Finterly/326bcdc53794412b0c8f7f75ce495ab2 to your computer and use it in GitHub Desktop.
USHatecrime Region Radar Chart
This file contains 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/v5.json", | |
"padding": { | |
"left": 250, | |
"top": 200 | |
}, | |
"width": 660, | |
"height": 480, | |
"autosize": { | |
"type": "none" | |
}, | |
"signals": [ | |
{ | |
"name": "radius", | |
"update": "80" | |
} | |
], | |
"data": [ | |
{ | |
"name": "tableW", | |
"url": "https://raw.githubusercontent.com/Finterly/Datasets_to_play_with/master/radarW" | |
}, | |
{ | |
"name": "keysW", | |
"source": "tableW", | |
"transform": [ | |
{ | |
"type": "aggregate", | |
"groupby": [ | |
"key" | |
] | |
} | |
] | |
}, | |
{ | |
"name": "tableNE", | |
"url": "https://raw.githubusercontent.com/Finterly/Datasets_to_play_with/master/radarNE" | |
}, | |
{ | |
"name": "keysNE", | |
"source": "tableNE", | |
"transform": [ | |
{ | |
"type": "aggregate", | |
"groupby": [ | |
"key" | |
] | |
} | |
] | |
}, | |
{ | |
"name": "tableMW", | |
"url": "https://raw.githubusercontent.com/Finterly/Datasets_to_play_with/master/radarMW" | |
}, | |
{ | |
"name": "keysMW", | |
"source": "tableMW", | |
"transform": [ | |
{ | |
"type": "aggregate", | |
"groupby": [ | |
"key" | |
] | |
} | |
] | |
}, | |
{ | |
"name": "tableS", | |
"url": "https://raw.githubusercontent.com/Finterly/Datasets_to_play_with/master/radarS" | |
}, | |
{ | |
"name": "keysS", | |
"source": "tableS", | |
"transform": [ | |
{ | |
"type": "aggregate", | |
"groupby": [ | |
"key" | |
] | |
} | |
] | |
} | |
], | |
"scales": [ | |
{ | |
"name": "angular", | |
"type": "point", | |
"range": { | |
"signal": "[-PI, PI]" | |
}, | |
"padding": 0.5, | |
"domain": { | |
"data": "tableNE", | |
"field": "key" | |
} | |
}, | |
{ | |
"name": "radial", | |
"type": "linear", | |
"range": { | |
"signal": "[0, radius]" | |
}, | |
"zero": true, | |
"nice": false, | |
"domain": { | |
"data": "tableNE", | |
"field": "n" | |
}, | |
"domainMin": 0 | |
}, | |
{ | |
"name": "color", | |
"type": "ordinal", | |
"domain": { | |
"data": "tableNE", | |
"field": "category" | |
}, | |
"range": { | |
"scheme": "category10" | |
} | |
} | |
], | |
"layout": { | |
"padding": 20, | |
"columns": 2 | |
}, | |
"marks": [ | |
{ | |
"title": { | |
"text": "West", | |
"fontSize": 20, | |
"signal": 90, | |
"dx": 15, | |
"dy": -10 | |
}, | |
"type": "group", | |
"encode": { | |
"update": { | |
"width": { | |
"value": 200 | |
}, | |
"height": { | |
"value": 200 | |
} | |
} | |
}, | |
"marks": [ | |
{ | |
"type": "group", | |
"name": "categories", | |
"zindex": 1, | |
"from": { | |
"facet": { | |
"data": "tableW", | |
"name": "facet", | |
"groupby": [ | |
"category" | |
] | |
} | |
}, | |
"marks": [ | |
{ | |
"type": "line", | |
"name": "category-line", | |
"from": { | |
"data": "facet" | |
}, | |
"encode": { | |
"enter": { | |
"interpolate": { | |
"value": "linear-closed" | |
}, | |
"x": { | |
"signal": "scale('radial', datum.n) * cos(scale('angular', datum.key))" | |
}, | |
"y": { | |
"signal": "scale('radial', datum.n) * sin(scale('angular', datum.key))" | |
}, | |
"stroke": { | |
"scale": "color", | |
"field": "category" | |
}, | |
"strokeWidth": { | |
"n": 1 | |
}, | |
"fill": { | |
"scale": "color", | |
"field": "category" | |
}, | |
"fillOpacity": { | |
"value": 0.1 | |
} | |
} | |
} | |
} | |
] | |
}, | |
{ | |
"type": "rule", | |
"name": "radial-grid", | |
"from": { | |
"data": "keysW" | |
}, | |
"zindex": 0, | |
"encode": { | |
"enter": { | |
"x": { | |
"value": 0 | |
}, | |
"y": { | |
"value": 0 | |
}, | |
"x2": { | |
"signal": "radius * cos(scale('angular', datum.key))" | |
}, | |
"y2": { | |
"signal": "radius * sin(scale('angular', datum.key))" | |
}, | |
"stroke": { | |
"value": "lightgray" | |
}, | |
"strokeWidth": { | |
"value": 1 | |
} | |
} | |
} | |
}, | |
{ | |
"type": "text", | |
"name": "key-label", | |
"from": { | |
"data": "keysW" | |
}, | |
"zindex": 1, | |
"encode": { | |
"enter": { | |
"x": { | |
"signal": "(radius + 5) * cos(scale('angular', datum.key))" | |
}, | |
"y": { | |
"signal": "(radius + 5) * sin(scale('angular', datum.key))" | |
}, | |
"text": { | |
"field": "key" | |
}, | |
"align": [ | |
{ | |
"test": "abs(scale('angular', datum.key)) > PI / 2", | |
"value": "right" | |
}, | |
{ | |
"value": "left" | |
} | |
], | |
"baseline": [ | |
{ | |
"test": "scale('angular', datum.key) > 0", | |
"value": "top" | |
}, | |
{ | |
"test": "scale('angular', datum.key) == 0", | |
"value": "middle" | |
}, | |
{ | |
"value": "bottom" | |
} | |
], | |
"fill": { | |
"value": "black" | |
}, | |
"fontWeight": { | |
"value": "bold" | |
} | |
} | |
} | |
}, | |
{ | |
"type": "line", | |
"name": "outer-line", | |
"from": { | |
"data": "radial-grid" | |
}, | |
"encode": { | |
"enter": { | |
"interpolate": { | |
"value": "linear-closed" | |
}, | |
"x": { | |
"field": "x2" | |
}, | |
"y": { | |
"field": "y2" | |
}, | |
"stroke": { | |
"value": "lightgray" | |
}, | |
"strokeWidth": { | |
"value": 1 | |
} | |
} | |
} | |
} | |
] | |
}, | |
{ | |
"title": { | |
"text": "Northeast", | |
"fontSize": 20, | |
"signal": 90, | |
"dx": 15, | |
"dy": -10 | |
}, | |
"type": "group", | |
"encode": { | |
"update": { | |
"width": { | |
"value": 200 | |
}, | |
"height": { | |
"value": 200 | |
} | |
} | |
}, | |
"marks": [ | |
{ | |
"type": "group", | |
"name": "categories", | |
"zindex": 1, | |
"from": { | |
"facet": { | |
"data": "tableNE", | |
"name": "facet", | |
"groupby": [ | |
"category" | |
] | |
} | |
}, | |
"marks": [ | |
{ | |
"type": "line", | |
"name": "category-line", | |
"from": { | |
"data": "facet" | |
}, | |
"encode": { | |
"enter": { | |
"interpolate": { | |
"value": "linear-closed" | |
}, | |
"x": { | |
"signal": "scale('radial', datum.n) * cos(scale('angular', datum.key))" | |
}, | |
"y": { | |
"signal": "scale('radial', datum.n) * sin(scale('angular', datum.key))" | |
}, | |
"stroke": { | |
"scale": "color", | |
"field": "category" | |
}, | |
"strokeWidth": { | |
"n": 1 | |
}, | |
"fill": { | |
"scale": "color", | |
"field": "category" | |
}, | |
"fillOpacity": { | |
"value": 0.1 | |
} | |
} | |
} | |
} | |
] | |
}, | |
{ | |
"type": "rule", | |
"name": "radial-grid", | |
"from": { | |
"data": "keysNE" | |
}, | |
"zindex": 0, | |
"encode": { | |
"enter": { | |
"x": { | |
"value": 0 | |
}, | |
"y": { | |
"value": 0 | |
}, | |
"x2": { | |
"signal": "radius * cos(scale('angular', datum.key))" | |
}, | |
"y2": { | |
"signal": "radius * sin(scale('angular', datum.key))" | |
}, | |
"stroke": { | |
"value": "lightgray" | |
}, | |
"strokeWidth": { | |
"value": 1 | |
} | |
} | |
} | |
}, | |
{ | |
"type": "text", | |
"name": "key-label", | |
"from": { | |
"data": "keysNE" | |
}, | |
"zindex": 1, | |
"encode": { | |
"enter": { | |
"x": { | |
"signal": "(radius + 5) * cos(scale('angular', datum.key))" | |
}, | |
"y": { | |
"signal": "(radius + 5) * sin(scale('angular', datum.key))" | |
}, | |
"text": { | |
"field": "key" | |
}, | |
"align": [ | |
{ | |
"test": "abs(scale('angular', datum.key)) > PI / 2", | |
"value": "right" | |
}, | |
{ | |
"value": "left" | |
} | |
], | |
"baseline": [ | |
{ | |
"test": "scale('angular', datum.key) > 0", | |
"value": "top" | |
}, | |
{ | |
"test": "scale('angular', datum.key) == 0", | |
"value": "middle" | |
}, | |
{ | |
"value": "bottom" | |
} | |
], | |
"fill": { | |
"value": "black" | |
}, | |
"fontWeight": { | |
"value": "bold" | |
} | |
} | |
} | |
}, | |
{ | |
"type": "line", | |
"name": "outer-line", | |
"from": { | |
"data": "radial-grid" | |
}, | |
"encode": { | |
"enter": { | |
"interpolate": { | |
"value": "linear-closed" | |
}, | |
"x": { | |
"field": "x2" | |
}, | |
"y": { | |
"field": "y2" | |
}, | |
"stroke": { | |
"value": "lightgray" | |
}, | |
"strokeWidth": { | |
"value": 1 | |
} | |
} | |
} | |
} | |
] | |
}, | |
{ | |
"title": { | |
"text": "Midwest", | |
"fontSize": 20, | |
"signal": 90, | |
"dx": 15, | |
"dy": -10 | |
}, | |
"type": "group", | |
"encode": { | |
"update": { | |
"width": { | |
"value": 200 | |
}, | |
"height": { | |
"value": 200 | |
} | |
} | |
}, | |
"marks": [ | |
{ | |
"type": "group", | |
"name": "categories", | |
"zindex": 1, | |
"from": { | |
"facet": { | |
"data": "tableMW", | |
"name": "facet", | |
"groupby": [ | |
"category" | |
] | |
} | |
}, | |
"marks": [ | |
{ | |
"type": "line", | |
"name": "category-line", | |
"from": { | |
"data": "facet" | |
}, | |
"encode": { | |
"enter": { | |
"interpolate": { | |
"value": "linear-closed" | |
}, | |
"x": { | |
"signal": "scale('radial', datum.n) * cos(scale('angular', datum.key))" | |
}, | |
"y": { | |
"signal": "scale('radial', datum.n) * sin(scale('angular', datum.key))" | |
}, | |
"stroke": { | |
"scale": "color", | |
"field": "category" | |
}, | |
"strokeWidth": { | |
"n": 1 | |
}, | |
"fill": { | |
"scale": "color", | |
"field": "category" | |
}, | |
"fillOpacity": { | |
"value": 0.1 | |
} | |
} | |
} | |
} | |
] | |
}, | |
{ | |
"type": "rule", | |
"name": "radial-grid", | |
"from": { | |
"data": "keysMW" | |
}, | |
"zindex": 0, | |
"encode": { | |
"enter": { | |
"x": { | |
"value": 0 | |
}, | |
"y": { | |
"value": 0 | |
}, | |
"x2": { | |
"signal": "radius * cos(scale('angular', datum.key))" | |
}, | |
"y2": { | |
"signal": "radius * sin(scale('angular', datum.key))" | |
}, | |
"stroke": { | |
"value": "lightgray" | |
}, | |
"strokeWidth": { | |
"value": 1 | |
} | |
} | |
} | |
}, | |
{ | |
"type": "text", | |
"name": "key-label", | |
"from": { | |
"data": "keysMW" | |
}, | |
"zindex": 1, | |
"encode": { | |
"enter": { | |
"x": { | |
"signal": "(radius + 5) * cos(scale('angular', datum.key))" | |
}, | |
"y": { | |
"signal": "(radius + 5) * sin(scale('angular', datum.key))" | |
}, | |
"text": { | |
"field": "key" | |
}, | |
"align": [ | |
{ | |
"test": "abs(scale('angular', datum.key)) > PI / 2", | |
"value": "right" | |
}, | |
{ | |
"value": "left" | |
} | |
], | |
"baseline": [ | |
{ | |
"test": "scale('angular', datum.key) > 0", | |
"value": "top" | |
}, | |
{ | |
"test": "scale('angular', datum.key) == 0", | |
"value": "middle" | |
}, | |
{ | |
"value": "bottom" | |
} | |
], | |
"fill": { | |
"value": "black" | |
}, | |
"fontWeight": { | |
"value": "bold" | |
} | |
} | |
} | |
}, | |
{ | |
"type": "line", | |
"name": "outer-line", | |
"from": { | |
"data": "radial-grid" | |
}, | |
"encode": { | |
"enter": { | |
"interpolate": { | |
"value": "linear-closed" | |
}, | |
"x": { | |
"field": "x2" | |
}, | |
"y": { | |
"field": "y2" | |
}, | |
"stroke": { | |
"value": "lightgray" | |
}, | |
"strokeWidth": { | |
"value": 1 | |
} | |
} | |
} | |
} | |
] | |
}, | |
{ | |
"title": { | |
"text": "South", | |
"fontSize": 20, | |
"signal": 90, | |
"dx": 15, | |
"dy": -10 | |
}, | |
"type": "group", | |
"encode": { | |
"update": { | |
"width": { | |
"value": 200 | |
}, | |
"height": { | |
"value": 200 | |
} | |
} | |
}, | |
"marks": [ | |
{ | |
"type": "group", | |
"name": "categories", | |
"zindex": 1, | |
"from": { | |
"facet": { | |
"data": "tableS", | |
"name": "facet", | |
"groupby": [ | |
"category" | |
] | |
} | |
}, | |
"marks": [ | |
{ | |
"type": "line", | |
"name": "category-line", | |
"from": { | |
"data": "facet" | |
}, | |
"encode": { | |
"enter": { | |
"interpolate": { | |
"value": "linear-closed" | |
}, | |
"x": { | |
"signal": "scale('radial', datum.n) * cos(scale('angular', datum.key))" | |
}, | |
"y": { | |
"signal": "scale('radial', datum.n) * sin(scale('angular', datum.key))" | |
}, | |
"stroke": { | |
"scale": "color", | |
"field": "category" | |
}, | |
"strokeWidth": { | |
"n": 1 | |
}, | |
"fill": { | |
"scale": "color", | |
"field": "category" | |
}, | |
"fillOpacity": { | |
"value": 0.1 | |
} | |
} | |
} | |
} | |
] | |
}, | |
{ | |
"type": "rule", | |
"name": "radial-grid", | |
"from": { | |
"data": "keysS" | |
}, | |
"zindex": 0, | |
"encode": { | |
"enter": { | |
"x": { | |
"value": 0 | |
}, | |
"y": { | |
"value": 0 | |
}, | |
"x2": { | |
"signal": "radius * cos(scale('angular', datum.key))" | |
}, | |
"y2": { | |
"signal": "radius * sin(scale('angular', datum.key))" | |
}, | |
"stroke": { | |
"value": "lightgray" | |
}, | |
"strokeWidth": { | |
"value": 1 | |
} | |
} | |
} | |
}, | |
{ | |
"type": "text", | |
"name": "key-label", | |
"from": { | |
"data": "keysS" | |
}, | |
"zindex": 1, | |
"encode": { | |
"enter": { | |
"x": { | |
"signal": "(radius + 5) * cos(scale('angular', datum.key))" | |
}, | |
"y": { | |
"signal": "(radius + 5) * sin(scale('angular', datum.key))" | |
}, | |
"text": { | |
"field": "key" | |
}, | |
"align": [ | |
{ | |
"test": "abs(scale('angular', datum.key)) > PI / 2", | |
"value": "right" | |
}, | |
{ | |
"value": "left" | |
} | |
], | |
"baseline": [ | |
{ | |
"test": "scale('angular', datum.key) > 0", | |
"value": "top" | |
}, | |
{ | |
"test": "scale('angular', datum.key) == 0", | |
"value": "middle" | |
}, | |
{ | |
"value": "bottom" | |
} | |
], | |
"fill": { | |
"value": "black" | |
}, | |
"fontWeight": { | |
"value": "bold" | |
} | |
} | |
} | |
}, | |
{ | |
"type": "line", | |
"name": "outer-line", | |
"from": { | |
"data": "radial-grid" | |
}, | |
"encode": { | |
"enter": { | |
"interpolate": { | |
"value": "linear-closed" | |
}, | |
"x": { | |
"field": "x2" | |
}, | |
"y": { | |
"field": "y2" | |
}, | |
"stroke": { | |
"value": "lightgray" | |
}, | |
"strokeWidth": { | |
"value": 1 | |
} | |
} | |
} | |
} | |
] | |
} | |
], | |
"legends": [ | |
{ | |
"fill": "color", | |
"orient": "top", | |
"x": 500, | |
"y": 200 | |
} | |
], | |
"config": {} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment