class: center, middle, inverse, title-slide # Day Twenty-Nine: Point Mapping ## SDS 192: Introduction to Data Science ###
Lindsay Poirier
Statistical & Data Sciences
, Smith College
###
Spring 2022
--- # For today 1. Projections 2. Coordinate Reference Systems 3. Point mapping in Leaflet --- # Why analyze spatial data? * How are features distributed across geographies, and what does this tell us about potential disparities? * Where are certain events or features concentrated, and what other conditions might implicate these patterns? * What kinds of features are proximate, and what impact might this have? * What is the best way to get from point A to point B? --- # Geographic Comparisons
--- # Concentrations of Features ## Where are the most were Missed Collections on October 1, 2021?
--- # Proximity Analysis: [Carceral EJ Mapper](https://critical-data-analysis.org/shiny/proximity/proximity-app/) ![](img/carceral-ej.png) --- # Projections <iframe width="560" height="315" src="https://www.youtube.com/embed/vVX-PrBRtTY" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe> --- # Projections * Means by which we convert curved surface of the globe to 2D rectangle * Necessarily distorts the surface (e.g. area, distance) * Many projections exist, serving different purposes --- # Orange Peel Example .pull-left[ * Imagine that you peel an orange * Datum is the original shape of the fruit (e.g. orange, lemon, apple, grapefruit) * Projection is how we go about peeling and flattening the orange ] .pull-right[ ![](https://geohackweek.github.io/visualization/assets/img/orange.png) > https://geohackweek.github.io/visualization/02-projections/ ] --- # Coordinate Reference System (CRS) * Points are in different locations depending on how we flatten Earth's surface into 2D map * CRS is a system for locating features on a certain map projection via coordinates * Thousands of CRSs but some are more common than others (e.g. WGS 84 most common) * For locations to appear correctly on maps, geographic features and underlying maps need to share same CRS --- # `sf` Package * Encodes spatial data * Enables setting and transforming CRSs ```r library(sf) library(readr) nyc_311 <- read_csv("https://data.cityofnewyork.us/resource/erm2-nwe9.csv?$select=latitude,longitude&$limit=4") %>% st_as_sf(coords = c("longitude", "latitude"), crs = 4269) #NAD 83 nyc_311 ``` ``` ## Simple feature collection with 4 features and 0 fields ## Geometry type: POINT ## Dimension: XY ## Bounding box: xmin: -73.98197 ymin: 40.61101 xmax: -73.87925 ymax: 40.75435 ## Geodetic CRS: NAD83 ## # A tibble: 4 × 1 ## geometry ## * <POINT [°]> ## 1 (-73.98197 40.73083) ## 2 (-73.87925 40.75435) ## 3 (-73.97674 40.61101) ## 4 (-73.95247 40.66224) ``` --- # How do I know which to use? * We pray that it's listed somewhere in data documentation. * Not always the case. --- # Leaflet * Start by calling `leaflet()` function, setting the original view, and adding basemap tiles ```r library(leaflet) leaflet() %>% setView(lat = 40.7, lng = -100.0, zoom = 3) %>% addProviderTiles("OpenStreetMap") ```
> Note that you need to look up the coordinates of the geography you wish to center in on. --- # Leaflet, cont. ```r library(leaflet) leaflet() %>% setView(lat = 40.7, lng = -74.0, zoom=10) %>% addProviderTiles("CartoDB.Positron") %>% addCircleMarkers(data = nyc_311) ``` ``` ## Warning: sf layer has inconsistent datum (+proj=longlat +datum=NAD83 +no_defs). ## Need '+proj=longlat +datum=WGS84' ```
> Notice the issue with the CRS here? --- # Leaflet, cont. ```r library(leaflet) nyc_311 <- nyc_311 %>% st_transform(4326) leaflet() %>% setView(lat = 40.7, lng = -74.0, zoom=10) %>% addProviderTiles("CartoDB.Positron") %>% addCircleMarkers(data = nyc_311) ```
--- # Layers ```r leaflet() %>% setView(lat = 40.7, lng = -74.0, zoom=10) %>% addProviderTiles("CartoDB.Positron") %>% addCircleMarkers(data = nyc_311_rodent, fillColor = "red") %>% addCircleMarkers(data = nyc_311_litter, fillColor = "blue") ```
--- # Palettes * `colorNumeric()`: Maps numbers to colors in a specified palette * `colorBin()`: Maps numbers into a specified intervals (e.g. 0-10, >10-20, etc.) * `colorQuantile()`: Maps numbers into a specified number of buckets (intervals calculated automatically) * `colorFactor()`: Maps categories into a specified number of buckets