Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A Vega-Lite distribution plot for temperature, further facted by City to observe geographic variability. Produced using Deneb for Power BI.
{
"data": {
"name": "dataset"
},
"facet": {
"row": {
"field": "City",
"header": {
"title": "",
"labelFontSize": 16,
"labelFontWeight": 500
}
}
},
"spec": {
"width": 600,
"height": 120,
"layer": [
{
"description": "IQR Rect",
"mark": {
"type": "rect",
"tooltip": null
},
"encoding": {
"x": {
"aggregate": "q1",
"field": "Mean Temperature"
},
"x2": {
"aggregate": "q3",
"field": "Mean Temperature"
}
}
},
{
"description": "Quantiles",
"transform": [
{
"quantile": "Mean Temperature",
"probs": [
0.05,
0.25,
0.5,
0.75,
0.95
]
}
],
"layer": [
{
"description": "Quantitle Lines",
"mark": {
"type": "rule",
"tooltip": null
},
"encoding": {
"x": {
"field": "value",
"type": "quantitative"
},
"color": {
"condition": [
{
"test": "datum.prob === 0.05 || datum.prob === 0.95",
"value": "#A8337D"
}
],
"value": "#0D6ABF"
},
"strokeDash": {
"condition": [
{
"test": "datum.prob === 0.5 || datum.prob === 0.05 || datum.prob === 0.95",
"value": [
1,
0
]
}
],
"value": [
0,
1
]
}
}
},
{
"description": "Quantitle Labels",
"mark": {
"type": "text"
},
"encoding": {
"x": {
"field": "value",
"type": "quantitative"
},
"text": {
"condition": [
{
"test": "datum.prob === 0.25",
"value": "Q1"
},
{
"test": "datum.prob === 0.5",
"value": "Median"
},
{
"test": "datum.prob === 0.75",
"value": "Q3"
}
],
"field": "prob",
"title": "Probability",
"format": ".0%"
},
"color": {
"condition": [
{
"test": "datum.prob === 0.05 || datum.prob === 0.95",
"value": "#A8337D"
},
{
"test": "datum.prob === 0.5",
"value": "#0D6ABF"
}
],
"value": "#605E5C"
}
}
}
]
},
{
"description": "Density Line Plot",
"transform": [
{
"density": "Mean Temperature",
"bandwidth": 0.4
}
],
"layer": [
{
"description": "Density Line",
"mark": {
"type": "line"
}
},
{
"description": "Mouse hover - Density Line",
"params": [
{
"name": "hover",
"select": {
"type": "point",
"on": "mouseover",
"clear": "mouseout",
"nearest": true,
"encodings": [
"x"
]
}
}
],
"mark": {
"type": "rule",
"tooltip": true,
"size": 1,
"color": "#8B8A88"
},
"encoding": {
"y": {
"value": "height"
},
"y2": {
"value": 0
},
"opacity": {
"condition": {
"param": "hover",
"value": 1,
"empty": false
},
"value": 0
}
}
}
],
"encoding": {
"x": {
"field": "value",
"title": "Temperature (°C)",
"type": "quantitative"
},
"y": {
"field": "density",
"type": "quantitative",
"title": "Sample Density",
"axis": {
"format": ".1%",
"title": ""
},
"scale": {
"domain": [
0,
0.15
]
}
}
}
}
]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment