d3 Choropleth map by county name

1,669 views
Skip to first unread message

tal y

unread,
Jan 25, 2013, 1:59:55 PM1/25/13
to d3...@googlegroups.com
Hi all,

I am compiling data that references county names and I've noticed that the d3 geoJSON files use zip codes.

How would I go about matching my county names to the right zips without having to do it all manually?

Thanks

Mike Bostock

unread,
Jan 25, 2013, 2:27:24 PM1/25/13
to d3...@googlegroups.com
If you're referring to the provided us.json TopoJSON example file (as
used in [1], for example), the id of each geometry is the 5-digit FIPS
code:

http://www.itl.nist.gov/fipspubs/co-codes/states.txt

The first two digits indicate the state code (d.id / 1000 | 0), and
the last three digits (d.id % 1000) are the county code. But note that
the id is encoded as an integer rather than a string, so it doesn’t
have leading zeroes. I've included a list of state names as a CSV file
here:

https://gist.github.com/4090846#file-us-state-names-tsv

I've not compiled a list of county names, so unless you find one
elsewhere you'd need to extract them from the states.txt link above.
Or I’ll add one if I get a chance.

Mike

[1] http://bl.ocks.org/4206573

Mike Bostock

unread,
Jan 25, 2013, 2:49:57 PM1/25/13
to d3...@googlegroups.com
I found a more convenient (but still official) source here:

http://coastwatch.pfeg.noaa.gov/erddap/convert/fipscounty.html

And it's now available cleaned up here:

https://gist.github.com/4090846#file-us-county-names-tsv

Mike

tal y

unread,
Jan 25, 2013, 2:58:53 PM1/25/13
to d3...@googlegroups.com
Thanks, this helps.

I still have some manual lifting to do but will post my list when it's complete.

I am organizing it into:

State / County / Code

That way when someone receives a dataset like the one I'm currently working with (no zip codes) they will be able to plot it much quicker.

Mike Bostock

unread,
Jan 25, 2013, 3:00:59 PM1/25/13
to d3...@googlegroups.com
> That way when someone receives a dataset like the one I'm currently working
> with (no zip codes) they will be able to plot it much quicker.

Zip codes are unrelated to FIPS codes. Zip codes don't correspond to
counties; they are actually aggregations of postal routes rather than
spatial subdivisions.

Mike

John Coogan

unread,
Jul 19, 2013, 4:37:02 PM7/19/13
to d3...@googlegroups.com
Hmmm... Given that I took IP addresses, looked them up in the MaxMind database and returned this JSON object (sample):

{'area_code': 410,
 'city': 'Hampstead',
 'country_code': 'US',
 'country_code3': 'USA',
 'country_name': 'United States',
 'dma_code': 512,
 'latitude': 39.6161994934082,
 'longitude': -76.82579803466797,
 'metro_code': 512,
 'postal_code': '21074',
 'region': 'MD',
 'region_name': 'Maryland',
 'time_zone': 'America/New_York'}

What's the easiest way to visualize this on a United States Choropleth map? Do you know of any shape files that have precision beyond the state level but don't use county codes? Can I map this data to county codes somehow? Should I try to use the lat / long via a hexbin?

Sorry for all the questions, hope something comes to mind.

Thanks!  

Adam

unread,
Jul 19, 2013, 4:48:15 PM7/19/13
to d3...@googlegroups.com
I used cityName + stateName to make a choropleth of Whitehouse petition signatures a couple of months ago. Not perfect, but it mostly works.

(both the code and webpage are pretty ugly...) 
Reply all
Reply to author
Forward
0 new messages