FlowingData today has an article on how to make a choropleth map (a map with regions shaded by values of a measurement variable) using free tools. The goal is to recreate this map:
The free tool FlowingData used is Python, and the whole process takes 14 steps and involves finding an SVG file with the county-level map and editing the SVG file with a text editor (automating part of that process with an XML tool in Python). At the end of the day the result is an SVG file -- high-resolution, yes, but not compatible with all browsers.
Surely this could be done more easily in R? You can create a county-level map with the maps library and the map("county") command (or you can use this method with the sp package), and the data are available as a CSV file which you can read in with read.csv. RColorBrewer should even generate the same color scheme. So I challenge the R hackers out there - let's show 'em how it's done in R.
FlowingData: How to Make a US County Thematic Map Using Free Tools (via @marcoscan)
Why don't you post that as question on stackoverflow? I was thinking the same thing when I read that blog entry on FlowingData this morning...
Posted by: Shane | November 12, 2009 at 10:15
Here's my attempt- http://gist.github.com/233134. It would be a lot more succinct with a better data source for the counties. Any suggestions?
Posted by: Hadley | November 12, 2009 at 10:18
Took me about twenty minutes - I found a shapefile with FIPS codes, read in with readOGR from package:rgdal, then read in the unemployment data with read.table, matched up the FIPS codes (two missing), then converted things to a factor to plot with the same colour scheme, used spplot for the graphic.
Python's BeautifulSoup of course is made for hacking XML files. I'd actually like to see him do it properly in Python using a shapefile and the various python map packages.
Neither gadm:
http://www.gadm.org/country
nor maplibrary:
http://www.maplibrary.org/stacks/gadm/USA/index.php
seemed to have FIPS codes in their maps of US counties.
Posted by: Barry Rowlingson | November 12, 2009 at 10:25
Here is mine.
http://gist.github.com/233257
It craps out a bit on a few counties since the maps(county) data has some strange names. Fun exercise though.
Posted by: Jason H | November 12, 2009 at 12:41
Love the challenge, David - here's my take:
http://www.thisisthegreenroom.com/2009/choropleths-in-r/
Posted by: J | November 12, 2009 at 19:13
This might help:
Figure 13.10
http://lmdvr.r-forge.r-project.org/figures/figures.html
Posted by: A.I. | November 13, 2009 at 08:39
And mine, using base graphics and census data.
http://gist.github.com/233956
http://files.eduardoleoni.com/map20091113.png
Posted by: Eduardo L | November 13, 2009 at 08:49
Good stuff...I used this as a springboard to create choropleth maps for all economic and demographic data in the u.s. census at StatJump
e.g. Check out the distribution of Italian population by county.
Posted by: Pat | June 30, 2010 at 12:08
I'm trying to do the same thing but for only one state. I tried getting the shape file and using readOGR but get an error message. Any idea how I could go about it? cheers
Posted by: clementine | January 09, 2011 at 14:09
Is the data for this available there still?
Posted by: LA Food Truck Map | February 26, 2011 at 17:29