Mapping Foodborne Chicago Reports

[This article was first published on Stats and things, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

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 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…

Check out Foodborne Chicago on twitter…

And myself on twitter…

To leave a comment for the author, please follow the link and comment on their blog: Stats and things. offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)