Today we discuss more on the theory and practical use cases of mapping, and learn to (superficially) work with shapefile data.

Next week, when we are deep in the soul-crushing debugging of Structured Query Language, think of shape-mapping, particularly where borders intersect and overlap, as a visual representation of "inner" and "outer" joins.

Related tutorial: Fusion Tables Intensity Maps with Custom Shapes

Voronoi cholera map

Continuing from last lesson's mention of John Snow…

Below is an interactive version of John Snow's cholera map. The red dots represent the casualties, the orange dots represent the pumps.

The shaded region around each pump represents the area in which that pump is the closest to, as the crow flies. Thus, the red dots within each pump's shaded region represent the casualties that were nearer to that pump than to the neighboring pump.

This is a simple Voronoi diagram to help better quantify the deaths of people whose main water source was the Broad Street pump.

Technical note: There are a few technical problems with this map, particularly my poor implementation of the D3 voronoi function and how the "deaths" were geocoded (the stacked dots all belong to a particular building/geopoint)…but it's meant to be a rough demonstration of the voronoi concept.

More technical notes: The digitized death point data comes from Rusty Dodson of NCGIA/Santa Barbara. The code to draw the map was inspired by Waldo Tobler's work here. The Voronoi-drawing code is a crude alteration of Mike Bostock's demonstration.

John Snow's hand-drawn Voronoi diagram

The voronoi-map diagram helps with visualizing each pump's "region of influence", but drawing the boundaries based on as-the-crow-flies distance misses an important nuance: lugging water containers, whether by hand or by wheeled-cart, cannot be done as if you were a bird. In other words, people will gravitate to a water pump in which the roads (or walkways) to get there are more convenient, even if the crows-flies distance is farther.

This was a nuance that Dr. Snow captured in this lesser-known version of his cholera map (which is considered a voronoi-type diagram, even though such a concept wasn't invented in Snow's time).

Via Stephen Johnson in "The Ghost Map: The Story of London's Most Terrifying Epidemic":

After presenting to the Epidemiological Society, Snow had realized that his original map was still vulnerable to a miasmatic interpretation. Perhaps the concentration of deaths around the Broad Street pump was merely evidence that the pump was releasing noxious fumes into the air. And so Snow realized he needed a way to represent graphically the foot-traffic activity around the pump that he had so painstakingly reconstructed. He needed to show lives, not just deaths; he needed to show the way the neighborhood was actually traversed by its residents.

via the John Snow archive:

The key takeaway is that the raw geographic data – location of the pumps, location of the dead residents – was not enough to make a scientific argument. Snow had to understand how the dead lived: the hand-drawn loop around the Broad Street pump is based off of his understanding of the traffic patterns at the human level, giving a more precise illustration of how people accessed the Broad Street pump.

And while the deaths inside the boundary line are interesting, if not conclusive evidence, the boundary line also makes it easy to identify counterexamples, i.e. anomalies that seem to contradict Dr. Snow's hypothesis.

These counterexamples underscore the strength of Dr. Snow's reporting and scientific method. There are at least two kinds "counterexamples" that are interesting:

There are several buildings within the voronoi-boundary that have strikingly few deaths. Dr. Snow investigated these individually. An example from Tufte's retrospective analysis: There is a brewer in Broad Street, near the pump, and on perceiving that no brewer's men were registered as having died of cholera, I called on Mr. Huggins, the propietor. He informed me that there were above seventy workmen employed in the brewery, and that none of them had suffered from cholera, at least in a severe form…The men are allowed a certain quantity of malt liquor, and Mr. Huggins believes they do not drink water at all…There is a deep well in the brewery, in addition to the New River water. There are clusters of deaths that are far from the Broad Street pump. In his investigation, Dr. Snow found that many residents willingly traveled a farther distance to the Broad Street pump because it was thought to have better-quality water.

So to continue hammering on the point: it's not the visualization, it's the reporting.

Near/inside a shape: Earthquakes and schools

via Center for Investigative Reporting: Palo Alto schools near seismic hazards

A good example of "joining" data: The shapefiles that represent the quicksand zones and fault lines are one dataset. The locations of schools are another dataset. Where the two intersect: that may be a story.

Outside a shape: Campaign contributions outside a district

via WNYC's John Keefe:

The 54th Assembly campaign contribution breakdown: Where have all the in-district donors gone?

Still, no one can really claim to be pulling their support–at least financially–directly from the people they represent.

Illustrative maps

In U.S. presidential elections, the most common way to show election results is via a state-by-state voting map. Via the NYT:

Reflect on why this map just works: if you're a long-time U.S. resident, you have a decent fix for what these shapes represent. In many cases, such as with "Florida", you're able to find it on this map much faster than you would in a standard list/table.

However, if you were completely unfamiliar with U.S. geography, this map would seem to illustrate an incredibly close political race, one in which "Red" seems to have won. And that's because without prior political knowledge, this kind of map ends up being not a map of political votes, but of geographic area, such that states like Montana and Ohio have an outsized/undersized visual impact.

To underscore this point, look at the vote tally by county: unless you have an impressive memorization of county-level demographics, this map very strongly conveys the impression of a Republican victory:

Cartogram

The cartogram is one kind of compromise to deal with the population-vs-geography mismatch. In the map below, each electoral vote is given the same size, and then placed roughly where it corresponds in relative geography. The tradeoff is that, well, it's not as easy to reflexively locate many of the less-influential states, such as Iowa:

Illustrative policy map: gun permit policies

Here's a non-election way of using the U.S. map to quickly show the state of state laws:

NYT Graphic: Easing Restrictions on Gun Permits

via Michael Luo of the New York Times:

NYT Graphic: Restoring Gun Rights

Illustrative policy map: failure-to-protect laws

We discussed BuzzFeed reporter Alex Campbell's investigation into failure-to-protect laws in the previous class. I'm including some notes and discussion here, as it is relevant for today's assignment.

Here's the illustrative U.S. map used in Campbell's story:

The deeper the red, the harsher the maximum sentence for a failure-to-protect conviction.

This is a decent example of using the U.S. map to illustrate the spread of policy, but I highlight this story's map in particular because they include the spreadsheet they use to build it. Here's what the sheet's layout looks like (split in half to better fit the page here):

Campbell's investigation also includes this sidebar with how cases were found, and the supporting spreadsheets are included. There's also a list of the kinds of data BuzzFeed asked for from each state.