Tuesday, November 20, 2012

Fun with Cartograms

A cartogram is a map in which the geometry is distorted so that the displayed area of a region matches some variable other than physical area.  Red/blue cartograms with US states distorted to reflect the number of electoral votes rather than the physical area become popular every four years.  Entire web sites have been created to distribute cartograms.  From time to time, I find myself wanting to generate a cartogram, but have lacked the appropriate software.  Last week I decided to do something about that.  I spent a day looking at various free packages available on the Internet.  Some wouldn't run on my Mac; some required learning obscure details of a complex user interface; some required map data in specific formats I didn't have available.

Ultimately, I decided to build my own little system around M.E.J. Newman's cart and interp programs.  The programs are written in vanilla C and compiled properly on my Mac [1].  The paper describing the detailed algorithm [2] is also available.  I already had a file with state outlines that I had obtained from Wikipedia.  A couple hundred lines of Perl later, and I had working code that would generate cartograms for the 48 contiguous states plus the District of Columbia, using Dr. Newman's programs to do the hardest part.  There's still a lot of details to attend to to make things a bit more general and more automatic, but at least I can play with maps.
The first map shown to the left is the basic undistorted map.  It's either a conic or equal-area projection of the continental US; the Wikipedia page doesn't say which.  That's not really important, as the two are essentially identical over this area.  The Wikipedia file has a couple of small errors in the outline descriptions that show up in certain drawings.  I corrected the worst one, but plan on obtaining different outlines at some point in the future anyway.

The next map is distorted so that the area of each state reflects its population.  The proportions are not perfect, but close.  The errors are probably due to my using too little padding around the map.  The Gastner and Newman paper discusses how much padding is appropriate, and I used less than they recommend.  In areas where the population density is roughly the same over adjacent states (eg, Illinois, Indiana, and Ohio) the shapes of the states are recognizable.  Where density changes drastically (eg, California) the shapes are more distorted.  This is the classic problem for cartograms -- how to adjust parameters so that things don't get distorted too badly.

The next map is distorted so that the area of each state represents the size of the federal land holdings within that state.  The same 11 states are shaded violet in this map and the preceding one.  It is one thing to read that most such holdings are in the West; the cartogram makes that painfully obvious.  The two violet areas can't be compared directly; the total areas of the 48 states in the two distorted maps don't match.  With some care, though, the diffusion algorithm should make it possible to set things up so that the maps can be compared.

Finally, just to show that I can do it, the basic red/blue map distorted by each state's electoral votes for the 2012 Presidential election.  Note how prominent Washington, DC becomes in this map, as it expands so its area is equal to that of the other states with three votes (eg, Wyoming and Vermont).  As always, there are lots of things that could be done with color shading to convey additional information.

[1] The programs depend on one external library for an implementation of the Fast Fourier Transform.  That library is also free, has been ported to many operating systems, and built just fine on my Mac.

[2] Michael T. Gastner and M. E. J. Newman (2004) Diffusion-based method for producing density equalizing maps, Proc. Natl. Acad. Sci. USA 101, 7499-7504.

No comments:

Post a Comment