[R] Plot by FIPS Code using Shapefiles

Roger Bivand Roger.Bivand at nhh.no
Wed May 6 12:23:58 CEST 2015

Corey Sparks <corey.sparks <at> utsa.edu> writes:

> Joining data the way you're doing it is dangerous, Roger Bivand and others
> describes a standard way to do this process here:

Quite right - the chunks Corey is referring to are:

Please do refer to the vignette in the maptools package, and to previous
threads which have advised that merge() should not be used, and that the
row.names of the data frames be used as ID keys. Typically using match() on
the row.names of the two objects will show which are not correctly aligned.


Beware that the data from the objects may be jumbled - never use merge,
always use match() on the row.names vectors of the objects to ensure that
the key-IDs agree. Jumbled data happens, it is important not to think
"shapefile" but to think DBMS with the ID key your way of staying sane. 

The maptools vignette is at:




Here I also suspect that you'll find that there are non-unique FIPS in the
county polygons file, so may need to go through
maptools::unionSpatialPolygons() first.


> And I do an example using US Census data here, using merge():
> http://spatialdemography.org/wp-content/uploads/2013/04/9.-Sparks.pdf
> <http://spatialdemography.org/wp-content/uploads/2013/04/9.-Sparks.pdf>  
> look at page 134 of that pdf.
> Hope this helps
> -----
> Corey Sparks, PhD
> Assistant Professor
> Department of Demography
> University of Texas at San Antonio
> 501 West César E. Chávez  Blvd 
> Monterey Building 2.270C
> San Antonio, TX 78207
> 210-458-3166
> corey.sparks 'at' utsa.edu
> coreysparks.weebly.com
> --
> View this message in context:
> Sent from the R help mailing list archive at Nabble.com.
> ______________________________________________
> R-help <at> r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.

More information about the R-help mailing list