Description Usage Arguments Value Author(s) References Examples
Calculates the area of each polygon in SpatialPolygonsDataFrame
.
1 |
sp.object |
|
a numeric vector.
Zack W. Almquist
Zack W. Almquist (2010). US Census Spatial and Demographic Data in R: The UScensus2000 Suite of Packages. Journal of Statistical Software, 37(6), 1-31. http://www.jstatsoft.org/v37/i06/.
Also see: SpatialPolygonsDataFrame
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | ############################################
## Helper function for handling coloring of the map
############################################
color.map<- function(x,dem,y=NULL){
l.poly<-length(x@polygons)
dem.num<- cut(dem,breaks=ceiling(quantile(dem)),dig.lab = 10)
dem.num[which(is.na(dem.num)==TRUE)]<-levels(dem.num)[1]
l.uc<-length(table(dem.num))
if(is.null(y)){
##commented out, but creates different color schemes
## using runif, may take a couple times to get a good color scheme.
##col.heat<-rgb( runif(l.uc,0,1), runif(l.uc,0,1) , runif(l.uc,0,1) )
col.heat<-heat.colors(16)[c(14,8,4,1)] ##fixed set of four colors
}else{
col.heat<-y
}
dem.col<-cbind(col.heat,names(table(dem.num)))
colors.dem<-vector(length=l.poly)
for(i in 1:l.uc){
colors.dem[which(dem.num==dem.col[i,2])]<-dem.col[i,1]
}
out<-list(colors=colors.dem,dem.cut=dem.col[,2],table.colors=dem.col[,1])
return(out)
}
############################################
## Helper function for handling coloring of the map
############################################
library(UScensus2000tract)
data(oregon.tract)
## Build density using areaPoly()
den00<-oregon.tract$pop2000/areaPoly(oregon.tract)
oregon.tract$den00<-den00
colors.use<-color.map(oregon.tract,oregon.tract$den00)
plot(oregon.tract,col=colors.use$colors,border="transparent")
title(main="Census Tracts \n of Oregon, 2000", sub="Quantiles (equal frequency)")
legend("bottomright",legend=colors.use$dem.cut,
fill=colors.use$table.colors,bty="o",
title="Population Density",bg="white")
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.