Skip to content

Instantly share code, notes, and snippets.

@PBI-DataVizzle
Created December 24, 2023 23:22
Show Gist options
  • Select an option

  • Save PBI-DataVizzle/bf7acb650dbe8f9d5299b026fe794df2 to your computer and use it in GitHub Desktop.

Select an option

Save PBI-DataVizzle/bf7acb650dbe8f9d5299b026fe794df2 to your computer and use it in GitHub Desktop.
dumbell_vl
{
"$schema": "https://vega.github.io/schema/vega-lite/v5.json",
"description": "A ranged dot plot that uses 'layer' to convey changing life expectancy for the five most populous countries (between 1955 and 2000).",
"data": {
"values": [
{"country": "China", "year": 1955, "life_expect": 41},
{"country": "China", "year": 2000, "life_expect": 72},
{"country": "India", "year": 1955, "life_expect": 37},
{"country": "India", "year": 2000, "life_expect": 62},
{"country": "United States", "year": 1955, "life_expect": 68},
{"country": "United States", "year": 2000, "life_expect": 77},
{"country": "Indonesia", "year": 1955, "life_expect": 35},
{"country": "Indonesia", "year": 2000, "life_expect": 68},
{"country": "Brazil", "year": 1955, "life_expect": 50},
{"country": "Brazil", "year": 2000, "life_expect": 71}
]
},
"transform": [{"filter": {"field": "year", "oneOf": [1955, 2000]}}],
"encoding": {
"x": {
"field": "life_expect",
"type": "quantitative",
"title": "Life Expectancy (years)"
},
"y": {
"field": "country",
"type": "nominal",
"title": "Country",
"axis": {"offset": 5, "ticks": false, "minExtent": 70, "domain": false}
}
},
"layer": [
{
"mark": "line",
"encoding": {
"detail": {"field": "country", "type": "nominal"},
"color": {"value": "#db646f"}
}
},
{
"mark": {"type": "point", "filled": true},
"encoding": {
"color": {
"field": "year",
"type": "ordinal",
"scale": {"domain": [1955, 2000], "range": ["#e6959c", "#911a24"]},
"legend": {"title": "Year", "orient": "right", "offset": 10}
},
"size": {"value": 100},
"opacity": {"value": 1}
}
}
],
"config": {"view": {"stroke": "transparent"}, "axis": {"domainWidth": 1}}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment