Maps 2 EPID 799C Fall 2017 To code along today: Have a county dataframe with FIPS Download Install packages galore: sp, rgdal, rgeos, tmap,
Today: Maps in R Quick Review Getting spatial data Read / write Merge Vis packages Data structures (sp/sf) Basic spatial operations Example map projects
Review from last time Types: Point, Line, Poly, Raster Shapefile structure QGIS Basics
Getting spatial data Tiger Files: https://www.census.gov/geo/maps- data/data/tiger-line.html NC One Map http://data.nconemap.gov/geoportal/catalog/main /home.page Geocode your own
Read/write ReadOGR writeOGR
Merge Exactly the same as spatial! (Thanks, overloading) new_df = merge(df1, df2) # by=… and all.x/all.y= parameters Important! 1. Do not merge the data by itself. I have done this. 2. Also: joining data can be a pain
Viz Packages base::plot() sp::spplot() ggplot tmap
Side note: There’s a new structure in town! Simple features (sf) spec – just a dataframe! The spatial information is stored as another “variable’ Not quite as efficient in some ways, but easier to work with. Can eventually overload dplyr functions. See cran page and many vignettes
Basic Spatial Operations spTransform() http://www.epsg.org/ , cheat sheet, spatial reference list gCentroid() gRelates() DE-9IM matrix gTouches() ^simple version of above aggregate() (spatial) gBuffer() over() and %over% workhorse. (SE example here) gDist() spSample … and many more
Let’s Try! Prepare your county tbl
Map Project Examples Title VI complaint Flood plain mapping Alcohol exposure index Linking police killing Police traffic stops / police