[R-sig-Geo] County-level map of the US

Corey Sparks corey.sparks at UTSA.EDU
Sat Apr 4 15:46:59 CEST 2009


Hi Phil,
I saw your post and have been doing this exact thing for the US  
recently.  Do you have a county shapefile?  You will need this to join  
your data (Y) to.  I typically use ArcGIS to join my attribute data   
to my shapefiles, but I don't know if you have access to this  
software.  This is ONE way to do it there are lots of different ways  
to plot geographic data in polygons, so hopefully this will get you  
started.

Here is an example from some of my work, you need 3 libraries (and  
their dependencies installed: classInt, maptools and RColorBrewer
library(classInt)
library(maptools)
library(RColorBrewer)

##Read in the us county shapefile, I had my data in Lambert Conformal  
Conic projected coordinate system, you would have to change the  
proj4string to what your projection is
usdat<-readShapeSpatial(fn="us.county.shp",  
proj4string=CRS("+proj=lcc"))

#Find the "break levels" for classifying numeric values of Y into  
discrete intervals, this uses the Jenks/Fisher method which looks  for  
natural breaks in the data
brks.Y<-classIntervals(usdat$Y, n=5, style="fisher")

#Define a color ramp of increasing intensity Blues
cols<-brewer.pal(5,"Blues")

#Plot the polygons, plotting each county with a color corresponding to  
its attribute value Y
plot(usdat, col=cols[findInterval(usdat$Y, brks.Y, all.inside=T)],  
border=0.1)
title(main="County Plot of Y")
labs<-leglabs(brks.Y, under="Under", over="Over", between="to")
legend("bottomleft",legend=labs, cex=.9, fill=brewer.pal(5,"Blues"))

If you need the US shapefile, you can get them from the Census  
Cartographic Boundary files:
http://www.census.gov/geo/www/cob/

Hope this gets you started
Corey

Corey Sparks
Assistant Professor
Department of Demography and Organization Studies
College of Public Policy
One UTSA Circle
San Antonio, TX 78239
corey.sparks at utsa.edu

Responding To:
Hi R-sig:

I'm just an old guy and new to this list... But have been using R for
years now.

I want to make a map of couties in the US with shaded colors that depend
on the level of variable "Y" that I want to map.

I have the US county and state fips codes and the Y variable.

How do I do this?

Please reply to pzs6 at cdc.gov

Thanks,
Phil Smith
pzs6 at cdc.gov



More information about the R-sig-Geo mailing list