This is an Rpubs test file!
setwd("/Users/erlisakabashi/Desktop/dida 370/midterm/zip_codes")
Warning: The working directory was changed to /Users/erlisakabashi/Desktop/dida 370/midterm/zip_codes inside a notebook chunk. The working directory will be reset when the chunk is finished running. Use the knitr root.dir option in the setup chunk to change the working directory for notebook chunks.
library(sf)
Linking to GEOS 3.11.0, GDAL 3.5.3, PROJ 9.1.0; sf_use_s2() is TRUE
library(ggplot2)
library(dplyr)
Attaching package: ‘dplyr’
The following objects are masked from ‘package:stats’:
filter, lag
The following objects are masked from ‘package:base’:
intersect, setdiff, setequal, union
library(urbnmapr)
Attaching package: ‘urbnmapr’
The following object is masked _by_ ‘.GlobalEnv’:
counties
map <- st_read("cb_2019_us_zcta510_500k.shp")
Reading layer `cb_2019_us_zcta510_500k' from data source
`/Users/erlisakabashi/Desktop/dida 370/midterm/zip_codes/cb_2019_us_zcta510_500k.shp'
using driver `ESRI Shapefile'
Simple feature collection with 33144 features and 5 fields
Geometry type: MULTIPOLYGON
Dimension: XY
Bounding box: xmin: -176.6847 ymin: -14.37374 xmax: 145.8304 ymax: 71.34132
Geodetic CRS: NAD83
colnames(map)[1] <- "zipcode"
map$zipcode <- as.numeric(map$zipcode)
map_ny <- map %>%
filter(zipcode > 09999 & zipcode < 15000)
ggplot(map_ny)+
geom_sf(fill = "white")
setwd("/Users/erlisakabashi/Desktop/dida 370/midterm/")
Warning: The working directory was changed to /Users/erlisakabashi/Desktop/dida 370/midterm inside a notebook chunk. The working directory will be reset when the chunk is finished running. Use the knitr root.dir option in the setup chunk to change the working directory for notebook chunks.
data <- read.csv("select_zipcode_statistics.csv")
library(tidyr)
library(tidyverse)
── Attaching core tidyverse packages ─────────────────────────────────────── tidyverse 2.0.0 ──
✔ forcats 1.0.0 ✔ readr 2.1.5
✔ lubridate 1.9.3 ✔ stringr 1.5.1
✔ purrr 1.0.2 ✔ tibble 3.2.1── Conflicts ───────────────────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag() masks stats::lag()
ℹ Use the ]8;;http://conflicted.r-lib.org/conflicted package]8;; to force all conflicts to become errors
#join shapefile with survey data
ny1 <- map_ny %>%
left_join(data, by = c("zipcode" = "Geographic.Area.Name")) %>% drop_na() %>%
st_transform("EPSG:32116")
#get just Broome county
#load in NYS county shape file and set crs
counties <- get_urbn_map("counties", sf = TRUE)
#filter the data to get just NYS
broome <- counties %>%
filter(state_abbv == "NY") %>%
filter(county_name == "Broome County") %>%
st_transform("EPSG:32116")
old-style crs object detected; please recreate object with a recent sf::st_crs()
#isolate Broome County
broome_map <- ny1[broome,]
#plot it
ggplot(broome_map)+
geom_sf(mapping = aes(), fill = "white")+
theme_minimal()+
labs(title = "Broome County Zipcodes")