Geoscience Reference
In-Depth Information
###################################################
### code chunk number 1: preamble
###################################################
options(width = 45)
library(xtable)
###################################################
### code chunk number 2: dataprep
###################################################
# http://www2.cdc.gov/nceh/lead/census90/house11/download.htm
# http://www2.cdc.gov/nceh/lead/census90/house11/houintro.htm
library('foreign')
library('maptools')
download.file(“http://www2.cdc.gov/nceh/lead/census90/house11/files/cnty.
zip”,”cnty.zip”)
unzip(“cnty.zip”)
gdat <- read.dbf('CNTY.dbf',as.is = TRUE)
gdat <- subset(gdat,gdat$STATE_NAME = =”Georgia”)
[,c(“P080A001”,”P0130001”,”CNTY_NAME”)]
# Get rid of space in 'De Kalb' so that county names in both data sets
match
gdat$CNTY_NAME[44] <- “DeKalb”
# http://www.census.gov/geo/www/cob/co1990.html
download.file(“http://www.census.gov/geo/cob/bdy/co/co90shp/co13_d90_shp.
zip”,”co13_d90_shp.zip”)
unzip(“co13_d90_shp.zip”)
georgia <- readShapePoly(“co13_d90”)
gdat <- gdat[match(as.character(georgia$NAME),gdat$CNTY_NAME),]
MedInc <- gdat$P080A001
Under1 <- gdat$P0130001
###################################################
### code chunk number 3: mappingtools
###################################################
library(RColorBrewer)
choropleth <- function (sp, v, shading = auto.shading(v),…)
{
i = shading$cols[1 + findInterval(v, shading$breaks)]
plot(sp, col = i,…)
}
auto.shading <- function(x,digits = 2,cutter = quantile.cuts,n = 5,params
= NA,cols = brewer.pal(n,'Reds'))
{
brk = cutter(x,n = n,params = params)
if (!is.na(digits)) brk = signif(brk,digits = digits)
brk = sort(brk)
brk = brk[!duplicated(brk)]
res = list(breaks = brk,cols = cols)
class(res) = 'shading'
res
}
Search WWH ::




Custom Search