I help out with a project called Foodborne Chicago, where we search twitter for people in Chicago mentioning “food poisoning” and @reply to them with a link where they can file a report with the city of Chicago’s Department of Public Health. The application has been live since March 2013. Since then, we have passed on about 125 reports to the city. For the majority of these reports, an inspection work order is generated and an inspection occurs within about a week of the incident submission.
So… I decided to take a look and see where these submissions were by plotting them on a map. To start, I had a file from our app with three columns, id which is a unique identifier of the submission, restaurant.address which is the address for the submission, and created.at which represents the date that the complaint was submitted. The first step to plotting these submissions on a map was to get the latitude and longitude for the restaurant addresses. I used the ggmap package for this. Originally, I had a custom function that used the free Google geocoding API and parsed the results, then I found the ggmap package and changed over. The results are the same, but it makes the code cleaner and easier to maintain.
Then, I Since I’ve used the OpenStreetMap package in R in another project, I started with that to make a map. The only gotcha here was that the OpenStreetMap package needs the points in mercator, so there’s a conversion step.
The ggmap package makes doing this sorta thing, in conjunction with ggplot2, very simple. Here’s the same map as above, using ggmap and Google maps.
Now, since I’m from the area and am not even sure where Chicago’s borders are on that map, I downloaded the shapefiles for Chicago from the city of Chicago and added that as an overlay on the map. All I did here was take the last plot (p2) and add the geom_polygon with a low alpha to the map.
This gives a pretty good representation of where our Foodborne Chicago submissions are coming from. Nearly all of them are on the northern half of the city, with a few from beyond the city limits altogether. It’s pretty remarkable how easy the ggmap and ggplot2 folks have made creating maps like this. Thanks guys…
The whole project, including making an animated gif and doing some cloudmade maps is on github here… https://github.com/corynissen/foodborne_chicago_report_map
Check out Foodborne Chicago on twitter… https://twitter.com/foodbornechi
And myself on twitter… https://twitter.com/corynissen