Taking Shape

Finding a Usable Map

To display a map of Philadelphia with our foreclosures, we need to find a polygon of the county as well as a means of plotting our lat/long coordinates onto it. Both these requirements are met by the ubiquitous ESRI shapefile format. The term shapefile collectively refers to a .shp file, which contains polygons, and related files which store other features, indices, and metadata.

Googling “philadelphia shapefile” returns several promising results including this page: http://www.temple.edu/ssdl/Shape_files.htm.

“Philadelphia Tracts” seems useful because it has US Census Tract information included. We can use these tract ids to link to other census data. Tracts are standardized to contain roughly 1500-8000 people, so densely populated tracts tend to be smaller. This particular shapefile is especially appealing because the map “projection” uses the same WGS84 Lat/Long coordinate system that our address geocoding service uses, as opposed to a “state plane coordinate system” which can be difficult to transform (transformations require the rgdal package and gdal executables).

Save and unzip the following to your project directory: http://en.wikipedia.org/wiki/World_Geodetic_System.

PBSmapping

PBSmapping is a popular R package that offers several means of interacting with spatial data. It relies on some base functions from the maptools package to read ESRI shapefiles, so we need both packages.

  > install.packages(c("maptools","PBSmapping"))

As with other packages ...

Get Data Mashups in R now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.