Database Reference
In-Depth Information
Turning Up the Heat
PBSmapping allows us to see in which polygons/tracts our foreclosures were plotted. Using
this data, we can represent the intensity of foreclosure events as a heatmap. We can use the
head function to inspect the first few rows of a data frame:
> addressPolys<-findPolys(addressEvents,myShapeFile)
> head(addressPolys)
EID PID SID Bdry
1 37 1 1 0
2 780 1 1 0
3 781 1 1 0
4 1164 1 1 0
5 1178 1 1 0
6 1179 1 1 0
Factors When You Need Them
Each EID (event ID, or foreclosure) is associated with a PID (polygon ID, or tract). To plot
our heatmap, we need to count instances of PIDs in addressPolys for each tract on the map.
> length(levels(as.factor(myShapeFile$PID)))
[1] 381
> length(levels(as.factor(addressPolys$PID)))
[1] 290
We can see that there are 381 census tracts in Philadelphia County, but only 290 have fore-
closure events. For the purpose of coloring our polygons, we need to ensure that the remainder
of the tracts are explicitly set to 0 foreclosures.
The table function in R can be used to make this sort of contingency table. We need a variable,
myTrtFC , to hold the number of foreclosures in each tract/PID:
> myTrtFC<-
table(factor(addressPolys$PID,levels=levels(as.factor(myShapeFile$PID))))
> head(myTrtFC)
1 2 3 4 5 6
7 3 0 1 0 0
To enforce our new levels, we must use a constructor ( factor ) instead of a variable conver-
sion ( as.factor ).
Search WWH ::




Custom Search