[R-sig-Geo] Creation of heatmaps with geocoded data

Reid Wodicka reid.wodicka at townofwoodstockva.gov
Tue Sep 3 20:29:17 CEST 2013


Hello all,

 

I am working on mapping the density of calls for service for our police
department in my town. Please excuse me because I'm completely self-teaching
R, so I'm probably pretty inefficient in my programming. Also, this is
probably a simple answer, so I apologize for that, but I hope someone can
help. 

 

The data that I have indicates the address of the call for service and I am
interested in aggregating to regions of the town so that I can create a heat
map that shows where in the town there are higher demands for service for
police. My strategy thus far has been to geocode the address points, then to
create a grid structure over the town, and then overlay the points to assign
them to a grid. Then, I would like to calculate the frequency of which a
cell has calls for service within it and create a heat map of the high
density demand locations. Then, I'd like to map it with an overlay of the
town streets (which I can do). 

 

Can anyone help on  where to do next? I can calculate frequencies after I've
converted the overlay output into a data frame, but I'm not sure how to add
that in as like an attribute to the Spatial Polygon structure that I've
created. I think this is almost like a join when you're using ArcMap, but
I'm not sure how to have that third variable for each cell and then plot it
with appropriate color codes. Any ideas on how to get to the next point?

 

Here is some of the code I've done so far, which has gotten me to the point
that I've geocoded the addresses, created a grid-like spatial polygon, and
then overlayed the points to the polygon, then created the df for the
overlay. 

 

library(gdata)

library(ggmap)

library(dismo)

library(XML)

library(PBSmapping)

library(rgeos)

library(sp)

library(gstat)

cfs<-read.xls("cfs.xlsx", sheet="Sheet1")

 

##create grid

grid<-GridTopology(c(-78.55, 38.85), c(0.0012, 0.0010), c(50,50))

grid.points<-SpatialPoints(grid)

grid.pixels<-SpatialPixels(grid.points)

poly<-as(grid.pixels, "SpatialPolygons")

plot(poly, col="white", border="grey", axes=T)

 

## geocode addresses and plot

add<-geocode(cfs$location.address, oneRecord=FALSE)

coordinates(add)<-c("longitude", "latitude")

plot(add, col="red", axes=T, add=T, pch=21)

 

##overlay incidents to grid

over<-overlay(poly,add)

over.df<-data.frame(over)

 

 

Thanks,

Reid

 

 

 

 

 

 

Reid A. Wodicka | Town Manager

Town of Woodstock, Virginia

135 North Main Street | Woodstock, Virginia 22664

Phone: 540-459-3621 | Fax: 540-459-3085

 <mailto:reid.wodicka at townofwoodstockva.gov>
reid.wodicka at townofwoodstockva.gov |  <http://www.townofwoodstockva.gov>
http://www.townofwoodstockva.gov

 

 <http://www.facebook.com/pages/Town-of-Woodstock-Virginia/201011663375674>
To find out the latest information, LIKE US on Facebook!

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20130903/df7a97e5/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: image/png
Size: 1082 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20130903/df7a97e5/attachment.png>


More information about the R-sig-Geo mailing list