Created
January 20, 2013 03:28
-
-
Save ajdamico/4576508 to your computer and use it in GitHub Desktop.
the puma of my childhood
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# install mapping packages | |
install.packages( c( 'sp' , 'rgdal' ) ) | |
# load necessary libraries | |
require(sp) | |
require(rgdal) | |
# create a temporary file and directory | |
tf <- tempfile() ; td <- tempdir() | |
# download the census state shape files | |
download.file( | |
"http://www.census.gov/geo/cob/bdy/st/st00shp/st24_d00_shp.zip" , | |
tf , | |
mode = 'wb' | |
) | |
# extract all files to the temporary directory | |
files <- unzip( tf , exdir = td ) | |
# find the shape file | |
sf <- files[ grepl( 'shp' , files ) ] | |
# read the shape file | |
state <- readOGR( sf , "st24_d00" ) | |
# download the maryland public use microdata area (puma) shape file | |
download.file( | |
"http://www.census.gov/geo/cob/bdy/pu/p500shp/p524_d00_shp.zip" , | |
tf , | |
mode = 'wb' | |
) | |
# extract all files to the temporary directory | |
files <- unzip( tf , exdir = td ) | |
# find the shape file | |
sf <- files[ grepl( 'shp' , files ) ] | |
# read both shape files | |
puma <- readOGR( sf , "p524_d00" ) | |
# plot the state boundary | |
plot( state ) | |
# plot just one puma | |
plot( puma[ puma$PUMA5 == '01004' , ] , col = 'blue' , add = TRUE ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment