Skip to content

Instantly share code, notes, and snippets.

@harishtella
Last active October 10, 2019 21:15
Show Gist options
  • Save harishtella/c2f866c443d240c65141f1cecb2856d5 to your computer and use it in GitHub Desktop.
Save harishtella/c2f866c443d240c65141f1cecb2856d5 to your computer and use it in GitHub Desktop.
Vega-lite: comparing heatmap and table-bubble-plot
{
"$schema": "https://vega.github.io/schema/vega-lite/v4.json",
"data": {"url": "data/cars.json"},
"transform": [
{
"aggregate": [{"op": "count", "as": "num_cars"}],
"groupby": ["Origin", "Cylinders"]
}
],
"resolve": {
"legend": {
"color": "independent",
"size": "independent"
}
},
"vconcat": [
{
"layer": [
{
"mark": {
"type": "rect",
"tooltip": true
},
"encoding": {
"y": {"field": "Origin", "type": "nominal"},
"x": {"field": "Cylinders", "type": "ordinal"},
"color": {"field": "num_cars", "type": "quantitative"}
}
},
{
"mark": "text",
"encoding": {
"y": {"field": "Origin", "type": "nominal"},
"x": {"field": "Cylinders", "type": "ordinal"},
"text": {"field": "num_cars", "type": "quantitative"},
"color": {
"condition": {"test": "datum['num_cars'] < 40", "value": "black"},
"value": "white"
}
}
}
]
},
{
"mark": {
"type": "circle",
"tooltip": true
},
"encoding": {
"y": {
"field": "Origin",
"type": "nominal"
},
"x": {
"field": "Cylinders",
"type": "ordinal"
},
"size": {
"type": "quantitative",
"field": "num_cars"
},
"opacity": {
"value": 1
}
}
}
]
}
{
"$schema": "https://vega.github.io/schema/vega-lite/v4.json",
"data": {"url": "data/cars.json"},
"resolve": {
"legend": {
"color": "independent",
"size": "independent"
}
},
"vconcat": [
{
"mark": {
"type": "rect",
"tooltip": true
},
"encoding": {
"y": {"field": "Origin", "type": "nominal"},
"x": {"field": "Cylinders", "type": "ordinal"},
"color": {"aggregate": "count", "type": "quantitative"}
}
},
{
"mark": {
"type": "circle",
"tooltip": true
},
"encoding": {
"y": {
"field": "Origin",
"type": "nominal"
},
"x": {
"field": "Cylinders",
"type": "ordinal"
},
"size": {
"type": "quantitative",
"aggregate": "count"
}
}
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment