Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

How to Plot 911 Police & Fire Responses in R

DZone's Guide to

How to Plot 911 Police & Fire Responses in R

· Big Data Zone
Free Resource

Effortlessly power IoT, predictive analytics, and machine learning applications with an elastic, resilient data infrastructure. Learn how with Mesosphere DC/OS.

Today I downloaded Seattle's dataset of over 438k 911 police responses for the city and plotted them in R. You can find the data I used and more here:  http://data.seattle.gov/

Here's the plot I created in R from this data:

 

Police_911_responses_in_seattle

 

First, compare my plot to this Google Map: 
View Larger Map

I've read about Facebook doing something similar and seeing maps formed, but I've never experienced it for myself. It was awesome to see it happen.

Also (and very unsurprisingly), notice how the darkest area with the most incidents is in downtown, and how abruptly the density changes at the city limits.

Here's how to do it yourself.

  1. Downloaded this specific dataset in CSV format: http://data.seattle.gov/Public-Safety/Seattle-Police-Department-911-Incident-Response/3k2p-39jp
  2. Load it into R by executing the following command: police_911 <- read.csv(file.choose())
  3. Find where you downloaded the file and open it
  4. Then I always use summary to quickly look at the data and get my bearings: summary(police_911)
  5. Notice the Longitude and Latitude columns? Already neatly parsed for us! Time to plot!
  6. plot(police_911$Longitude, police_911$Latitude, pch=20, cex=.01)

That's it! The pch and cex parameters allow me to set the point shape and size respectively. By executing length(police_911$Latitude), I can find out how many rows there are in that column... 438,512. Schiesse!

Update: Here's a map with Fire responses added to it as well. Blue is police and red is fire.

 

Police__fire_911_responses
 

Learn to design and build better data-rich applications with this free eBook from O’Reilly. Brought to you by Mesosphere DC/OS.

Topics:

Published at DZone with permission of Justin Bozonier, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}