I hope this isn't a basic question, I've had a hard time finding online resources for using R with shapefiles. I have a shapefile of the 5 digit zip codes in Texas, specifically the one at the bottom of this page.
I'm loading the zip code data and plotting it as such:
> library(maptools)
> zipData <- readShapePoly('~/Documents/Shapefiles/zipCodesTX/tl_2009_48_zcta5.shp')
> plot(zipData)
However, this yields the full map of Texas. I'd like to pare it down to just Dallas.
I thought about using zipData@bbox
to find the max values and using xlim
and ylim
to shrink it down from there, however, this causes the y and x axis to have different amounts.
> zipData@bbox
min max
x -106.64565 -93.50844
y 25.83723 36.99566
> plot(zipData, xlim <- c(-100, -95))
Error in xy.coords(x, y, xlabel, ylabel, log) :
'x' and 'y' lengths differ
Does anyone have an idea of an easy way to do this?
Further basic shapeplot question: How does plot()
actually plot my shapefile? names(zipData)
reveals the names of the data frame columns as:
> names(zipData)
[1] "ZCTA5CE" "CLASSFP" "MTFCC" "FUNCSTAT"
[5] "ALAND" "AWATER" "INTPTLAT" "INTPTLON"
Obviously, INTPTLAT
and INTPTLON
are lat and long coordinates, but plotting these as:
> plot(zipData$INTPTLAT, zipData$INTPTLON)
yields a big black box. How exactly are maps generated using plot()
with shapefiles?
I apologize if these questions are very base, I just could not find a good resource or explanation of this.