Skip to content

FigureFactory for zipcode/US choropleth maps - Discussion #897

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Kully opened this issue Dec 11, 2017 · 4 comments
Closed

FigureFactory for zipcode/US choropleth maps - Discussion #897

Kully opened this issue Dec 11, 2017 · 4 comments

Comments

@Kully
Copy link
Contributor

Kully commented Dec 11, 2017

No description provided.

@jackparmer
Copy link
Contributor

I think we want essentially this notebook by Emilia, but streamlined as a FigureFactory.

The most time consuming part to figure out may be parsing state-level TopoJSON down from US-level TopoJSON. We can host whichever TopoJSON file(s) we use as github.com/plotly/datasets. County TopoJSON for the entire US is here:
https://raw.githubusercontent.com/jgoodall/us-maps/master/topojson/county.topo.json

@empet , do you remember where you sourced the Texas TopoJSON file?

I'm imagining a syntax along these lines:

fig = FF.create_choropleth(scope='usa', mapping={48129: 5.3, ...}, colorscale=cs, hover=['Hansford County...', ...])

The FigureFactory would automatically download the TopoJSON from GitHub and parse it based on the scope parameter. mapping is a dict where the key is the county id and the value is whatever you're plotting (unemployment, voter turnout, etc).

It seems like we should start with "FIPS codes" as the regional county classification.

If this ends up being popular, there are number of additions we could try later:

  • Other regional TopoJSON classifications (zip code, census tracts)
  • Static D3 renderer (without zoom) in addition to this mapboxgl renderer
  • Other countries (India, Europe, etc)
  • Different TopoJSON resolutions (low rez for zooming and rendering speed, high rez for small states, etc)

@Kully First task is probably to prototype a US-level choropleth map and make sure the interactivity speed (zoom, hover, pan) feels good for the resolution of TopoJSON you choose. Then see if you can parse just state TopoJSON from the same file.

@jackparmer
Copy link
Contributor

Some nice county-level data for download here:
https://www.cdc.gov/nchs/data-visualization/drug-poisoning-mortality/

image

@empet
Copy link

empet commented Dec 14, 2017

@jackparmer I googled for "Texas topojson, github" and found this file: https://github.com/TNRIS/tx.geojson/tree/master/counties

@jackparmer
Copy link
Contributor

jackparmer commented Jan 12, 2018

I think the first version of this should actually use the SVG renderer rather than Mapbox. I've had some good results with US counties and SVG by disabling zoom.

The recipe is outlined here in this function get_figure:
https://github.com/plotly/dash-opioid-epidemic-demo/blob/master/app.py#L74

There are probably perf. improvements this recipe is missing that would improve load time time, something to keep in mind. This recipe generates this map:

image

(via https://opioid-epidemic.herokuapp.com/)

The data to draw the US shapefiles is here:
https://github.com/plotly/dash-opioid-epidemic-demo/tree/master/data

These shapefiles should be shipped in:
https://github.com/plotly/plotly.py/tree/master/plotly/package_data
So the user doesn't need an internet connection to make these maps.

For call signature, I'm thinking along the lines of:

fig = FF.create_choropleth(scope='usa', mapping={48129: 5.3, ...}, colorscale=cs, hover=['Hansford County...', ...])

It would also be great to offer collections of states (either abbreviation or full state name):

fig = FF.create_choropleth(scope=['VT', 'New Hampshire'], mapping={48129: 5.3, ...}, colorscale=cs, hover=['Hansford County...', ...])

Zoom should be locked by default.

Let's merge an SVG version ASAP, then can explore a mabox-gl version if there is demand.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants