Skip to main content

Introduction to Data Science Version 3

Chapter 16 Map MashUp

Much of what we have accomplished so far has focused on the standard rectangular dataset: one neat table with rows and columns well defined. Yet much of the power of data science comes from bringing together difference sources of data in complementary ways. In this chapter we combine different sources of data to make a unique product that transcends any one source.
Mashup is a term that originated in the music business decades ago related to the practice of overlaying one music recording on top of another one. The term has entered general usage to mean anything that brings together disparate influences or elements. In the application development area, mashup often refers to bringing together various sources of data to create a new product with unique value. There’s even a non-profit group called the Open Mashup Alliance that develops standards and methods for creating new mashups.
One example of a mashup is http://www.housingmaps.com/ , a web application that grabs apartment rental listings from the classified advertising service Craigslist and plots them on an interactive map that shows the location of each listing. If you have ever used Craigslist you know that it provides a very basic text-based interface and that the capability to find listings on a map would be welcome.
In this chapter we tackle a similar problem. Using some address data from government records, we call the Google geocoding API over the web to find the latitude and longitude of each address. Then we plot these latitudes and longitudes on a map of the U.S. This activities reuses skills we learned in the previous chapter for reading in data files, adds some new skills related to calling web APIs, and introduces us to a new type of data, namely the shapefiles that provide the basis for electronic maps.

R Functions Used in This Chapter.

Addr2latlng() - A custom function built for this chapter
addPoints() - Place more points on an existing plot
as.character() - Coerces data into a character string
as.EventData() - Coerce a regular dataframe into an EventData object for use with PBSmapping routines.
data.frame() - Takes individual variables and ties them together
for() - Runs a loop, iterating a certain number of times depending upon the expression provided in parentheses
fromJSON() - Takes JSON data as input and provides a regular R dataframe as output
function() - Creates a new function
importShapeFile() - Gets shapefile data from a set of ESRI compatible polygon data files
MakeGeoURL() - Custom helper function built for this chapter
paste() - Glues strings together
plotPolys() - Plots a map from shape data
rbind() - Binds new rows on a dataframe
return() - Specifies the object that should be returned from a function
URLencode() - Formats a character string so it can be used in an HTTP request
Sources