Skip to content

Instantly share code, notes, and snippets.

@jonmmease
Created July 17, 2022 12:53
Show Gist options
  • Save jonmmease/fdb8e4014499467fdca84898397ec087 to your computer and use it in GitHub Desktop.
Save jonmmease/fdb8e4014499467fdca84898397ec087 to your computer and use it in GitHub Desktop.
Heat Lane 2
{
"$schema": "https://vega.github.io/schema/vega-lite/v5.json",
"description": "Heatlane chart: https://www.smashingmagazine.com/2022/07/accessibility-first-approach-chart-visual-design/",
"data": {"url": "data/cars.json"},
"height": 150,
"width": 400,
"title": "Heatlane",
"transform": [
{
"bin": true,
"field": "Horsepower",
"as": ["bin_Horsepower_start", "bin_Horsepower_end"]
},
{
"aggregate": [{"op": "count"}],
"groupby": ["bin_Horsepower_start", "bin_Horsepower_end"]
},
{"bin": true, "field": "count", "as": ["bin_count_start", "bin_count_end"]},
{"calculate": "-datum.bin_count_end/2", "as": "y2"},
{"calculate": "datum.bin_count_end/2", "as": "y"},
{
"joinaggregate": [
{"field": "bin_count_end", "op": "max", "as": "max_bin_count_end"}
]
}
],
"encoding": {
"x": {
"field": "bin_Horsepower_start",
"type": "quantitative",
"title": "Horsepower",
"axis": {"grid": false}
},
"x2": {"field": "bin_Horsepower_end"},
"y": {"field": "y", "axis": null},
"y2": {"field": "y2"}
},
"layer": [
{
"mark": {
"type": "bar",
"xOffset": 2,
"x2Offset": -2,
"color": "black",
"cornerRadius": 3
},
"encoding": {
"color": {
"field": "max_bin_count_end",
"type": "ordinal",
"title": "count",
"scale": {"scheme": "lighttealblue"}
}
}
},
{
"mark": {
"type": "bar",
"xOffset": 2,
"x2Offset": -2,
"yOffset": -3,
"y2Offset": 3
},
"encoding": {
"color": {"field": "bin_count_end", "type": "ordinal", "title": "count"}
}
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment