title: Mapping Zip Code vs. County shapefile in R
body: <p>I am trying to map the polygons for various geographic areas (i.e. county/zip codes).  Based on what I have found at <a href="http://zevross.com/blog/2014/04/11/using-r-to-quickly-create-an-interactive-online-map-using-the-leafletr-package/" rel="nofollow noreferrer">this blog</a> I can easily accomplish this for counties.</p>
  
  <pre><code>library(rgdal)
  library(rgeos)
  library(leaflet)
  
  url&lt;-"http://www2.census.gov/geo/tiger/TIGER2010DP1/County_2010Census_DP1.zip"
  downloaddir&lt;-getwd()
  destname&lt;-"tiger_county.zip"
  download.file(url, destname)
  unzip(destname, exdir=downloaddir, junkpaths=TRUE)
  
  filename&lt;-list.files(downloaddir, pattern=".shp", full.names=FALSE)
  filename&lt;-gsub(".shp", "", filename)
  
  # ----- Read in shapefile (NAD83 coordinate system)
  # ----- this is a fairly big shapefile and takes 1 minute to read
  dat&lt;-readOGR(downloaddir, "County_2010Census_DP1") 
  
  # ----- Create a subset of New York counties
  subdat&lt;-dat[substring(dat$GEOID10, 1, 2) == "36",]
  
  # ----- Transform to EPSG 4326 - WGS84 (required)
  subdat&lt;-spTransform(subdat, CRS("+init=epsg:4326"))
  
  # ----- save the data slot
  subdat_data&lt;-subdat@data[,c("GEOID10", "ALAND10")]
  
  # ----- simplification yields a SpatialPolygons class
  subdat&lt;-gSimplify(subdat,tol=0.01, topologyPreserve=TRUE)
  
  # ----- to write to geojson we need a SpatialPolygonsDataFrame
  subdat&lt;-SpatialPolygonsDataFrame(subdat, data=subdat_data)
  
  leaflet() %&gt;%
    addTiles() %&gt;%
    addPolygons(data=subdat)
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/4WXIP.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/4WXIP.png" alt="enter image description here"></a></p>
  
  <p>But if I run the exact same code with a different file for zip codes</p>
  
  <pre><code>url &lt;- "http://www2.census.gov/geo/tiger/GENZ2014/shp/cb_2014_us_zcta510_500k.zip"
  </code></pre>
  
  <p>I get a completely different area of the country instead of New York.  </p>
  
  <p><a href="https://i.stack.imgur.com/nUsCS.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/nUsCS.png" alt="enter image description here"></a></p>
  
  <p>Not sure if someone is more familiar with these datasets and these functions to explain why this difference happens?</p>