Learn R Programming

cholera: amend, augment and aid analysis of Snow’s cholera map

package features

  • Fixes three apparent coding errors in Dodson and Tobler’s 1992 digitization of Snow’s map.
  • “Unstacks” the data in two ways to make analysis and visualization easier and more meaningful.
  • Computes and visualizes “pump neighborhoods” based on Euclidean distance (Voronoi tessellation) and walking distance.
  • Overlay graphical elements and features like kernel density estimates, Voronoi diagrams, Snow’s Broad Street neighborhood, and notable landmarks (John Snow’s residence, the Lion Brewery, etc.) via add*() functions.
  • Includes a variety of functions to find and highlight cases, roads, pumps and paths.
  • Appends street names to the roads data set.
  • Includes the revised pump data used in the second version of Snow’s map from the Vestry report, which also includes the “correct” location of the Broad Street pump.
  • Adds two aggregate time series fatalities data sets, taken from the Vestry report.
  • Support for parallel computation on Linux, macOS and Windows.
  • With ‘cholera’ version >= 0.8.0, preliminary and provisional support for georeferenced (longitude and latitude) versions of data and functions. Details below.

getting started

To install ‘cholera’ from CRAN:

install.packages("cholera")

To install the current development version from GitHub:

# You may need to first install the 'remotes' via install.packages("remotes").
remotes::install_github("lindbrook/cholera", build_vignettes = TRUE)

background

John Snow’s map, published in his On The Mode Of Communication Of Cholera, of the 1854 cholera outbreak in London is one of the best known examples of data visualization and information design:

By plotting the number and location of fatalities using stacks of bars on a map, Snow was able to perform a task that is now easily taken for granted: he visualized a spatial distribution. Looking at the results, the pattern on the map seems unmistakable. The map appears to support Snow’s claims that cholera is a waterborne disease and that the pump on Broad Street is the source of the outbreak.

And yet, despite its virtues, the map failed to convince either the authorities or Snow’s colleagues in the medical and scientific communities. Even today, many are skeptical of the map’s ability to support such claims. Beyond considerations of time and place, what critics past and present are picking up on is that a concentration of cases around the Broad Street pump alone should not be enough to convince us. The problem is the map does not refute the primary rival explanation to waterborne transmission: the pattern we see is not unlike what airborne transmission (miasma theory) might look like. In other words, while the presence of a pump at or near the epicenter of the distribution of fatalities is strong circumstantial evidence, it is nonetheless circumstantial.

pump neighborhoods

This may be the reason why Snow added a graphical annotation to a second lesser-known version of the map, published in the Report On The Cholera Outbreak In The Parish Of St. James, Westminster, During The Autumn Of 1854.

Despite its hand-drawn, back-of-the-envelope appearance, Snow writes: “The inner dotted line on the map shews [sic] the various points which have been found by careful measurement to be at an equal distance by the nearest road from the pump in Broad Street and the surrounding pumps …” (Ibid., p. 109). My interpretation of this statement is that, guided by the principle that all else being equal people tend to choose the closest pump, Snow is computing a pump neighborhood: the set of addresses or locations defined by their relative proximity to a specific water pump. By doing so, Snow’s annotation sets limits on where we should and should not find fatalities. In short, Snow’s annotation is a hypothesis or prediction.

computing pump neighborhoods

While his actual data and the specifics method of computation appear to be lost to history, I reverse engineer what I infer to be his approach by doing the following. First, from the quotation above I assume that his measure of proximity is the walking distance along the streets of Soho. Second, putting aside aside questions about the map’s accuracy (it’s actually a commercial map that Snow annotated), I consider the map to be the definitive “text” and make it the de facto source of data.

I then wrote functions that compute and visualize walking distances on the map. The value of these functions go beyond the ability to replicate and validate Snow’s efforts. By allowing you to compute hypothetical neighborhoods via selective inclusion or exclusion of pumps or to allow for different measures of proximity (e.g., Euclidean), they also allow you to explore counterfactual scenarios. Ultimately, this can help us to better assess whether we really can use the map to “prove” Snow’s claims.

walking v. Euclidean neighborhoods

While walking distanced based neighborhoods are based on paths that follow streets, Euclidean distance based neighborhoods are based on straight line paths between a location and the nearest (or selected) pump:

streetNameLocator(zoom = 1, cases = NULL, highlight = FALSE, add.subtitle = FALSE, add.title = FALSE)
title(main = "Walking Distances")
invisible(lapply(c(1, 191, 46, 363, 85), addWalkingPath))

streetNameLocator(zoom = 1, cases = NULL, highlight = FALSE, add.subtitle = FALSE, add.title = FALSE)
title(main = "Euclidean Distances")
invisible(lapply(c(1, 191, 46, 363, 85), addEuclideanPath))

To build a neighborhood, we apply this algorithm to each location or “address” with at least one observed fatality. This builds the “observed” neighborhood:

plot(neighborhoodWalking())
plot(neighborhoodEuclidean())

Ultimately, for testing purposes we want the “expected” neighborhoods. For walking neighborhoods, I use the same approach but use simulated data. Using sp::spsample() and sp::Polygon(), I place 20,000 regularly spaced points, which lie approximately 6 meters apart, unitMeter(dist(regular.cases[1:2, ])), across the face of the map and then compute the shortest path to the nearest pump.

plot(neighborhoodWalking(case.set = "expected"), "area.polygons")

For Euclidean distance based neighborhoods, we can use the same simulated data and compute the as-the-crow-flies distance to the nearest pump. Or, we can leverage a more computationally efficient approach, Voronoi tessellation, which will produce the same neighborhoods.

plot(neighborhoodEuclidean(case.set = "expected"))
plot(neighborhoodVoronoi())

exploring walking neighborhoods

To explore “observed” walking neighborhoods, use neighborhoodWalking() with the pump.select argument:

plot(neighborhoodWalking(pump.select = 6:7))
plot(neighborhoodWalking(pump.select = -7))

To explore “expected” walking neighborhoods, add the case.set = “expected” argument:

plot(neighborhoodWalking(pump.select = 6:7, case.set = "expected"), type = "area.polygons")
plot(neighborhoodWalking(pump.select = -7, case.set = "expected"), type = "area.polygons")

exploring Euclidean neighborhoods

To explore “observed” Euclidean neighborhoods, use neighborhoodEuclidean() with the pump.select argument:

plot(neighborhoodEuclidean(pump.select = 6:7))
plot(neighborhoodEuclidean(pump.select = -7))

To explore “expected” Euclidean neighborhoods, use neighborhoodVoronoi() with the pump.select argument:

plot(neighborhoodVoronoi(pump.select = 6:7))
plot(neighborhoodVoronoi(pump.select = -7))

parallelization

Parallelization is implemented using the ‘parallel’ package, which is part of the base R distribution. Where applicable, parallelization is enabled by default via multi.core = TRUE (you can also set or limit the number of cores by passing an integer or by setting multi.core = FALSE. Note that although some precautions are taken in the R application, the developers of the ‘parallel’ package strongly discourage against using parallelization within a GUI or embedded environment. See vignette("Parallelization") for details. That said, I’ve had few, if any, problems with using the package in parallel on macOS with either the R application or the RStudio IDE.

longitude and latitude

‘cholera’ now has preliminary, limited support for georeferenced (longitude and latitude) versions of some data and functions. This support goes beyond a proof of concept but is currently less than a complete re-implementation of the package’s native (non-georeferenced) functionality. The georeferencing was done manually using QGIS; specifically its Georeferencer tool and its interface to OpenStreetMap. The target coordinate reference system (CRS) of these data is EPSG:4326. What makes this effort preliminary is that the choice of ground control points, transformation type (e.g., thin plate spine), and resampling method (e.g., nearest neighbor) are still in flux. Thus, results and coordinates may change in the future.

Four functions are available:

snowMap(latlong = TRUE)
plot(latlongNeighborhoodVoronoi(), euclidean.paths = TRUE)
plot(latlongWalkingPath())
plot(latlongNeighborhoodWalking())

vignettes

The vignettes are available in the package as well as online at the links below.

Duplicate and Missing Cases describes the two coding errors and the three misplaced cases that I argue are present in Dodson and Tobler’s (1992) digitization of Snow’s map.

“Unstacking” Bars discusses the inferential and visual reasons to “unstack” bars. Then, it describes the two “unstacked” data sets: one using “fatalities” and one using “addresses” as the unit of observation.

Roads covers issues related to roads. This includes discussion of how and why I move pump #5 from Queen Street (I) to Marlborough Mews, the overall structure of the roads data set, “valid” road names, and my back-of-the-envelope translation from the map’s nominal scale to meters (and yards).

voronoiPolygons(): Tiles, Triangles and Polygons focuses on the voronoiPolygons() function, which extracts the vertices of triangles (Delaunay triangulation) and tiles (Dirichelet or Voronoi tessellation) from deldir::deldir() for use with polygon() and other functions.

Kernel Density Plot discusses the the syntax of addKernelDensity(), which allows you to define “populations” and subsets of pumps. This syntax is used in many of the functions in ‘cholera’.

Time Series discusses functions and data related to the aggregate time series fatalities data and the questions surrounding the effect of the removal of the handle from the Broad Street pump.

Parallelization discusses the parallelization of selected functions and provides benchmark timings.

lab notes

The lab notes, which are only available online, go into detail about certain issues and topics discussed in the vignettes:

note on duplicate and missing cases documents the specifics of how I fixed the two apparent coding errors and three apparently misplaced case in Dodson and Tobler’s data.

computing street addresses discusses how I use orthogonal projection and hierarchical cluster analysis to “unstack” bars and compute a stack’s “address”.

Euclidean v. Voronoi neighborhoods discusses why there are separate functions, neighborhoodEuclidean() and neighborhoodVoronoi(), for Euclidean distance based neighborhoods.

points v. polygons discusses the tradeoff between using points() and polygon() to plot “expected” neighborhood using area plots and the computation of polygon vertices.

computing Voronoi diagrams with geographic data describes the problems and a working solution for computing Voronoi diagrams with data that use latitude and longitude.

references is an informal list of articles and books about cholera, John Snow and the 1854 outbreak.

Copy Link

Version

Install

install.packages('cholera')

Monthly Downloads

590

Version

0.8.0

License

GPL (>= 2)

Issues

Pull Requests

Stars

Forks

Maintainer

Peter Li

Last Published

March 1st, 2023

Functions in cholera (0.8.0)

addKernelDensity

Add 2D kernel density contours.
addSnow

Adds Snow's graphical annotation of the Broad Street pump walking neighborhood.
addIndexCase

Highlight index case at 40 Broad Street.
addMilePosts

Add distance or time based "mileposts" to an observed walking neighborhood plot.
anchor.case

Anchor or base case of each stack of fatalities.
addLandmarks

Add landmarks to plot.
cholera-package

cholera: amend, augment and aid analysis of John Snow's cholera map
addWhitehead

Add Rev. Henry Whitehead's Broad Street pump neighborhood.
addWalkingPath

Add the shortest walking path between a selected cases or pumps.
addFrame

Add map border to plot.
fatalities.unstacked

"Unstacked" amended cholera fatalities data with fatality as unit of observation.
frame.data

Map frame data c("x", "y") and c("lon", "lat").
addEuclideanPath

Add the path for the Euclidean distance between cases and/or pumps.
border

Numeric IDs of line segments that create the map's border frame.
isoLines

Plot isochrone and isodistance regions (prototype)
addDelaunay

Add Delaunay triangles.
frame.sample

Partitioned map frame points (segment endpoints).
landmark.squares

Centers of city squares.
addNeighborhoodWalking

Add expected walking neighborhoods.
addPump

Add selected pump(s) to plot.
mapRange

Compute xlim and ylim of Snow's map.
addRoads

Add all streets and roads to plot.
caseDistance

Compute distance between case fatalities.
neighborhoodWalking

Compute walking path pump neighborhoods.
neighborhoodVoronoi

Compute Voronoi pump neighborhoods.
nearestPump

Compute shortest distances or paths to selected pumps.
fixFatalities

Fix errors in Dodson and Tobler's digitization of Snow's map.
euclideanPath

Compute path of the Euclidean distance between cases and/or pumps.
latlongVoronoi

Compute Georeferenced Latitude and Longitude of vertices of Voronoi polygons.
latlong.ortho.addr

Orthogonal projection of observed address (latlong) cases onto road network.
oxfordWeather

Weather data recorded in Oxford (Met Office UK).
latlongFatalities

Compute latitude and longitude of non-address fatalities (prototype).
latlongLandmarks

Compute Georeferenced Latitude and Longitude (prototype).
latlongNeighborhoodData

Compute network graph of roads, cases and pumps.
latlongNearestPump

Compute shortest georeferenced distances (and walking paths) to selected pumps (prototype).
caseLocator

Locate case by numerical ID.
addPlaguePit

Add plague pit (Marshall Street).
latlongPumps

Compute Georeferenced Latitude and Longitude (prototype).
fatalities.address

"Unstacked" amended cholera data with address as unit of observation.
fatalities

Amended Dodson and Tobler's cholera data.
landmarkData

Landmark data.
latlong.ortho.pump

Orthogonal projection of 13 original pumps (latlong).
plague.pit

Plague pit coordinates.
latlongWalkingPath

Plot walking path to nearest pump (prototype).
latlongRoads

Compute latitude and longitude for unique road segment endpoints (prototype).
latlongAddress

Compute latitude and longitude of case "addresses" (prototype).
oxford.weather

Oxford monthly weather data, January 1853 - December 2019.
ortho.proj

Orthogonal projection of observed cases onto road network.
ortho.proj.pump.vestry

Orthogonal projection of the 14 pumps from the Vestry Report.
latlong.ortho.pump.vestry

Orthogonal projection of the 14 pumps from the Vestry Report (latlong).
plot.neighborhood_data

Plot method for neighborhoodData().
plot.oxfordWeather

Plot method for oxfordWeather().
plot.latlongNeighborhoodVoronoi

Plot method for latlongNeighborhoodVoronoi()
ortho.proj.pump

Orthogonal projection of 13 original pumps.
plot.latlong_neighborhood_data

Plot method for latlongNeighborhoodData().
print.walking_path

Print method for walkingPath().
pumpData

Compute pump coordinates.
print.euclidean

Print method for neighborhoodEuclidean().
profile2D

2D Profile .
print.euclidean_path

Print method for euclideanPath().
latlongNeighborhoodWalking

Compute walking path pump neighborhoods.
roadSegments

Reshape 'roads' data frame into 'road.segments' data frame.
roads

Dodson and Tobler's street data with appended road names.
latlongNeighborhoodVoronoi

Compute Voronoi pump neighborhoods (lat-long prototype).
print.iso

Print method for isoVertices().
print.time_series

Print summary data for timeSeries().
streetNameLocator

Locate road by name.
print.latlong_walking_path

Print method for latlongWalkingPath().
print.latlongNeighborhoodVoronoi

Print method for latlongNeighborhoodVoronoi().
segmentLocator

Locate road segment by ID.
sim.ortho.proj

Road "address" of simulated (i.e., "expected") cases.
rd.sample

Sample of road intersections (segment endpoints).
pumps.vestry

Vestry report pump data.
plot.latlong_walking

Plot method for latlongNeighborhoodWalking().
plot.latlong_walking_path

Plot the walking path between selected cases and/or pumps.
summary.euclidean

Summary method for neighborhoodEuclidean().
summary.walking

Summary method for neighborhoodWalking().
pumpFatalities

Compute fatalities by pump.
streetNames

Street names (alphabetized).
landmarks

Orthogonal projection of landmarks onto road network.
rectangle.filter

Rectangular filter data.
regular.cases

"Expected" cases.
plot.winterTemperatures

Plot method for winterTemperatures().
summary.voronoi

Summary method for neighborhoodVoronoi().
winterTemperatures

Average Winter Temperatures.
neighborhoodData

Compute network graph of roads, cases and pumps.
neighborhoodEuclidean

Compute Euclidean path pump neighborhoods.
povertyLondon

Poverty and Born in London.
print.voronoi

Print method for neighborhoodVoronoi().
plot.euclidean

Plot method for neighborhoodEuclidean().
pumpLocator

Locate water pump by numerical ID.
print.walking

Print method for neighborhoodWalking().
simulateFatalities

Generate simulated fatalities.
plot.euclidean_path

Plot the path of the Euclidean distance between cases and/or pumps.
plot.time_series

Plot aggregate time series data from Vestry report.
plot.voronoi

Plot Voronoi neighborhoods.
timeSeries

Aggregate time series fatality data from the Vestry report.
pumps

Dodson and Tobler's pump data with street name.
segmentHighlight

Highlight segment by ID.
snowNeighborhood

Plotting data for Snow's graphical annotation of the Broad Street pump neighborhood.
snowMap

Plot John Snow's cholera map.
simulateWalkingDistance

Compute walking distance for simulated cases.
plot.walking

Plot method for neighborhoodWalking().
plot.walking_path

Plot the walking path between selected cases and/or pumps.
streetHighlight

Highlight road by name.
segmentLength

Compute length of road segment.
plot.profile_perspective

Plot method for profilePerspective().
profile3D

3D Profile.
pumpCase

Extract numeric case IDs by pump neighborhood.
plot.povertyLondon

Plot method for povertyLondon().
roadSegmentFix

Bar orientation classification errors.
road.segments

Dodson and Tobler's street data transformed into road segments.
snowColors

Create a set of colors for pump neighborhoods.
unstackFatalities

Unstack "stacks" in Snow's cholera map.
voronoi.polygons

Coordinates of Voronoi polygon vertices for original map.
voronoi.polygons.vestry

Coordinates of Voronoi polygon vertices for Vestry Report map.
snow.neighborhood

Snow neighborhood fatalities.
unitMeter

Convert nominal map distance to meters or yards.
streetLength

Compute length of selected street.
subsetRoadsSamples

Sample for road segment endpoints.
streetNumberLocator

Locate road by numerical ID.
voronoiPolygons

Extract vertices of Delaunay triangles and Dirichelet (Voronoi) tiles.
sim.walking.distance

Walking distance to Broad Street Pump (#7).
sim.pump.case

List of "simulated" fatalities grouped by walking-distance pump neighborhood.
walkingPath

Compute the shortest walking path between cases and/or pumps.
addNeighborhoodEuclidean

Add expected Euclidean pump neighborhoods.
addNeighborhoodCases

Add observed cases by neighborhood.
addCase

Add observed case(s) to plot.
addVoronoi

Add Voronoi cells.