{
"$schema": "https://vega.github.io/schema/vega/v5.json",
"description": "A choropleth map depicting U.S. unemployment rates by county in 2009.",
"width": 960,
"height": 500,
"autosize": "none",
"data": [
{
"name": "unemp",
"url": "data/population_engineers_hurricanes.csv",
"format": {"type": "csv", "parse": "auto"}
},
{
"name": "states",
"url": "data/us-10m.json",
"format": {"type": "topojson", "feature": "states"},
"transform": [
{ "type": "lookup", "from": "unemp", "key": "id", "fields": ["id"], "values": ["population"] },
{ "type": "filter", "expr": "datum.population != null" },
{
"type": "joinaggregate",
"fields": ["population"],
"groupby": ["id"],
"ops": ["sum"],
"as": ["a_count"]
}
]
}
],
"projections": [
{
"name": "projection",
"type": "albersUsa"
}
],
"scales": [
{
"name": "color",
"type": "quantize",
"range": {"scheme": "blues"}
}
],
"legends": [
{
"fill": "color",
"orient": "bottom-right",
"title": "Population",
"format": "0.0f"
}
],
"marks": [
{
"type": "shape",
"from": {"data": "states"},
"encode": {
"enter": { "tooltip": {"signal": "format(datum.a_count, '0.0f')"}},
"update": { "fill": {"scale": "color", "field": "a_count"} },
"hover": { "fill": {"value": "red"} }
},
"transform": [
{ "type": "geoshape", "projection": "projection" }
]
}
]
}
Output :
I wanted it to apply color as per sum of population for each state, but it is applying same color for all the states. May I know how I have color differentiation based on a_count field ?