Re: [R] Graphically show population density for a specific geographicarea using R

From: Roger Bivand <Roger.Bivand_at_nhh.no>
Date: Mon, 21 May 2007 22:18:24 +0200 (CEST)


On Mon, 21 May 2007, Greg Snow wrote:

> 1. Yes you need a shape file with that information.
>
> 2. One place to look is:
> http://www.census.gov/geo/www/cob/bdy_files.html There are shapefiles
> (the .shp ones) for counties and zip codes (as well as many other
> things). These work pretty directly with the tools in the maptools and
> sp packages.
>
> 3. Read the .shp file in using maptools, the .dbf information is
> automatically read in as well (with whatever details come with the
> shapefile), then look at the structure of what you read in, you will see
> the data frame and you should be able to just add your data into that
> data frame, or use it seperately.

wget http://www.census.gov/geo/cob/bdy/zt/z500shp/zt17_d00_shp.zip unzip zt17_d00_shp.zip
R

ill_zip <- readShapePoly("zt17_d00.shp", proj4string=CRS("+proj=longlat")) names(ill_zip)
summary(ill_zip)
plot(ill_zip, axes=TRUE)

suggests that there is no useful attribute data in the shapefile. It is in geographical coordinates, so that the AREA variable is not in useful coordinates. If you look at the codes, you'll see that some are represented by multiple polygons, especially the HH codes (water features). Also note that ZCTA are not the same as Postal ZIP Codes, according to the FAQ.

The easiest way to map a variable at the moment is:

spplot(ill_zip, "AREA")
> ill_zip$HH <- FALSE
> ill_zip$HH[grep("HH", as.character(ill_zip$NAME))] <- TRUE
> spplot(ill_zip, "HH")

only AREA doesn't tell you anything. You'll need to look for data for ZCTAs or similar, and if you need to compute the areas, project to something suitable and extract the values from the underlying SpatialPolygons object.

Finally, you'll need up-to-date numbers of inhabitants, as at this scale, a housing development can easily date your data.

I suggest you follow up on R-sig-geo.

Roger

>
> 4. plot.Map has an option auxvar, though it is now prefered to use the
> plot methods for the more specific objects (SpatialLinesDataFrame object
> from the readLinesShape function). I would expect that they would have
> an auxvar or similar argument also. Or you can decide what color you
> want to use, plot the overall map, then add each county/zipcode
> individually using the specified color.
>
> Hope this helps,
>
>

-- 
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Helleveien 30, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: Roger.Bivand_at_nhh.no

______________________________________________
R-help_at_stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Received on Mon 21 May 2007 - 20:23:00 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 21 May 2007 - 21:31:55 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.