class: center, middle, inverse, title-slide # Spatial data visualization ## Intro to Data Science ### Shawn Santo --- ## Today's agenda - Compare `sf` objects and tibbles - Visualize spatial data - Wrangle spatial data with `dplyr` --- ## Announcements - Soft deadline for Lab 03 is February 11 at 11:59pm ET - Soft deadline for Homework 02 is February 12 11:59pm ET - Review feedback on past assignments - Complete the Qualtrics survey (link is available in Slack in `#general`) --- ## Getting started - Create your personal private repository by clicking https://classroom.github.com/a/3jLTUvyI - Follow the steps as we have done previously to clone this and create a new RStudio project in the RStudio Docker containers. - Part of the data used in these slides is given in your repo. The other data for these slides is available through [NC OneMap](https://www.nconemap.gov/datasets/e5ddff9b96204c6181be7c022e61d946_0) --- class: middle, center, inverse # Spatial data --- ## Raster versus vector spatial data **Vector** spatial data describes the world using shapes (points, lines, polygons, etc). **Raster** spatial data describes the world using cells of constant size. <center> <img src="images/vector_raster_comparison.png" height=250 width=300> </center> The choice to use vector or raster data depends on the problem context. We will focus on vector data. *Source:* https://commons.wikimedia.org/wiki/File:Raster_vector_tikz.png --- ## Geometries visualized Simple features have a geometry type. Common choices are below. <img src="lec_07_files/figure-html/unnamed-chunk-3-1.png" style="display: block; margin: auto;" /> --- ## Spatial data plotting needs care <img src="lec_07_files/figure-html/unnamed-chunk-4-1.png" style="display: block; margin: auto;" /> --- ## Map Layers The North Carolina Department of Environment and Natural Resources, Wildlife Resources Commission and the NC Center for Geographic Information and Analysis has a [shapefile data set](https://www.nconemap.gov/datasets/e5ddff9b96204c6181be7c022e61d946_0) available on all public Game Lands in NC. .tiny[ ```r nc <- st_read("data/nc_covid.shp", quiet = TRUE) nc_game <- st_read("data/gamelands.shp", quiet = TRUE) ``` ] .tiny[ ```r nc_game %>% print(n = 5) ``` ``` #> Simple feature collection with 94 features and 6 fields #> geometry type: MULTIPOLYGON #> dimension: XY #> bbox: xmin: -84.29534 ymin: 33.98542 xmax: -75.54947 ymax: 36.58814 #> geographic CRS: NAD27 #> First 5 features: #> OBJECTID GML_HAB SUM_ACRES GameLandID Shape__Are Shape__Len #> 1 1 Alcoa 11395.947 1 69931121 549030.42 #> 2 2 Alligator River 24439.089 2 151120825 186792.83 #> 3 3 Angola Bay 34063.447 3 204400526 105421.80 #> 4 4 Bachelor Bay 2786.258 4 17219484 32891.84 #> 5 5 Bertie County 3883.768 5 24044312 83468.94 #> geometry #> 1 MULTIPOLYGON (((-80.07347 3... #> 2 MULTIPOLYGON (((-76.11832 3... #> 3 MULTIPOLYGON (((-77.86947 3... #> 4 MULTIPOLYGON (((-76.73896 3... #> 5 MULTIPOLYGON (((-76.9209 35... ``` ] --- ```r ggplot(nc_game) + geom_sf() + theme_bw() + labs(title = "North Carolina gamelands") ``` <img src="lec_07_files/figure-html/unnamed-chunk-7-1.png" style="display: block; margin: auto;" /> --- ```r ggplot(nc_game) + geom_sf(fill = "#ff6700") + theme_bw() + labs(title = "North Carolina gamelands") ``` <img src="lec_07_files/figure-html/unnamed-chunk-8-1.png" style="display: block; margin: auto;" /> --- ```r ggplot(nc) + geom_sf() + geom_sf(data = nc_game, fill = "#ff6700", alpha = .5) + theme_bw() + labs(title = "North Carolina gamelands and counties") ``` <img src="lec_07_files/figure-html/unnamed-chunk-9-1.png" style="display: block; margin: auto;" /> --- ```r ggplot(nc) + geom_sf() + geom_sf(data = nc_game, aes(alpha = SUM_ACRES), fill = "#ff6700") + theme_bw() + labs(title = "North Carolina gamelands and counties", alpha = "Acres") ``` <img src="lec_07_files/figure-html/unnamed-chunk-10-1.png" style="display: block; margin: auto;" />