singleview_6_25_map.vg.json 1.63 KB
Newer Older
Danyel Fisher committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
{
  "$schema": "https://vega.github.io/schema/vega/v3.0.json", 
  "config":{"background":"#ffffff"},
  "width": 900,
  "data": [
    {
      "name": "income",
      "url": "data/income.csv",
      "format": {
        "type": "csv",
        "parse": {"id": "number","value": "number"}
      },
      "transform": [
        {"type": "filter","expr": "datum.key=='200000+'"},
        {
          "type": "aggregate",
          "groupby": ["id","value"]
        }
      ]
    },
    {
      "name": "states",
      "url": "data/us-10m.json",
      "format": {"type": "topojson","feature": "states"},
      "transform": [
        {
          "type": "lookup",
          "from": "income",
          "key": "id",
          "fields": ["id"],
          "as": ["income"]
        },
        {"type": "filter","expr": "datum.income != null"}
      ]
    }
  ],
  "projections": [{"name": "projection","type": "albersUsa"}],
  "scales": [
    {
      "name": "color",
      "type": "quantize",
      "domain": {"data": "income","field": "value"},
      "range": {"scheme": "viridis"}
    }
  ],
  "legends": [
    {
      "fill": "color",
      "orient": "right",
      "title": "% with income $200000+",
      "encode": {
        "symbols": {
          "update": {
            "shape": {"value": "square"},
            "stroke": {"value": "#ccc"},
56
            "strokeWidth": {"value": 5}
Danyel Fisher committed
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
          }
        }
      }
    }
  ],
  "marks": [
    {
      "type": "shape",
      "from": {"data": "states"},
      "encode": {
        "update": {"fill": {"scale": "color","field": "income.value"}}
      },
      "transform": [{"type": "geoshape","projection": "projection"}]
    }
  ]
}