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

From: Roger Bivand <>
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:
> 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 unzip

ill_zip <- readShapePoly("zt17_d00.shp", proj4string=CRS("+proj=longlat")) names(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.


> 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

______________________________________________ mailing list
PLEASE do read the posting guide
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 Please read the posting guide before posting to the list.