Skip to content

Instantly share code, notes, and snippets.

@Jverma
Created January 28, 2017 10:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Jverma/ed7b536fa3c6ebfcf5b8857a2eff6b43 to your computer and use it in GitHub Desktop.
Save Jverma/ed7b536fa3c6ebfcf5b8857a2eff6b43 to your computer and use it in GitHub Desktop.
India GDP across states
<!DOCTYPE html>
<img src="states_wealth.svg" width="960" height="1100">
<img src="legend.svg" width="1000" height="1000">
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
#!/bin/bash
sudo npm install -g d3-geo-projection
geoproject 'd3.geoMercator().scale(6700).translate([-1240, 720]).fitSize([960, 960], d)' < states.json > states_proj.json
sudo npm install -g ndjson-cli
ndjson-split 'd.features' < states_proj.json > states.ndjson
ndjson-join 'd.id' states.ndjson wealth.json > states_wealth_join.ndjson
sudo npm install -g d3
ndjson-map 'd[0].properties = {wealth: d[1].value}, d[0]' < states_wealth_join.ndjson > states_wealth.ndjson
npm install -g topojson
geo2topo -n \
tracts=states_wealth.ndjson \
> states_wealth_topo.json
topo2geo tracts=- < new_states_topo.json | ndjson-map -r d3 -r d3=d3-scale-chromatic 'z=d3.scaleThreshold().domain([1, 5000, 20000, 40000, 50000, 60000, 80000, 100000, 120000, 150000]).range(d3.schemeOrRd[9]), d.features.forEach(f => f.properties.fill=z(f.properties.wealth)), d' | ndjson-split 'd.features' | geo2svg -n --stroke none -p 1 -w 960 -h 960 > states_wealth.svg
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment