Benjamin She 9/13/2021
library(tidyverse)
library(tidycensus)
library(sf)
library(tmap) # mapping, install if you don't have it
set.seed(717)
This assignment if for you to complete a short version of the lab notes,
but you have to complete a number of the steps yourself. You will then
knit this to a markdown (not an HTML) and push it to your GitHub repo.
Unlike HTML, the RMarkdown knit to github_document
can be viewed
directly on GitHub. You will them email your lab instructor with a link
to your repo.
Steps in this assignment:
-
Make sure you have successfully read, run, and learned from the
MUSA_508_Lab2_sf.Rmd
Rmarkdown -
Find two new variables from the 2019 ACS data to load. Use
vars <- load_variables(2019, "acs5")
andView(vars)
to see all of the variable from that ACS. Note that you should not pick something really obscure like count_38yo_cabinetmakers because you will get lots of NAs. -
Pick a neighborhood of the City to map. You will need to do some googling to figure this out. Use the PHL Track Explorer to get the
GEOID10
number from each parcel and add them to themyTracts
object below. This is just like what was done in the exercise, but with a different neighborhood of your choice. Remember that all GEOIDs need to be 10-characters long. -
In the first code chunk you will do that above and then edit the call-outs in the dplyr pipe sequence to
rename
andmutate
your data. -
You will transform the data to
WGS84
by adding the correct EPSG code. This is discussed heavily in the exercise. -
You will produce a map of one of the variables you picked and highlight the neighborhood you picked. There are call-out within the
ggplot
code for you to edit. -
You can run the code chunks and lines of code as you edit to make sure everything works.
-
Once you are done, hit the
knit
button at the top of the script window (little blue knitting ball) and you will see the output. Once it is what you want… -
Use the
Git
tab on the bottom left of right (depending on hour your Rstudio is laid out) and click the check box tostage
all of your changes, write a commit note, hit thecommit
button, and then thePush
button to push it to Github. -
Check your Github repo to see you work in the cloud.
-
Email your lab instructor with a link!
-
Congrats! You made a map in code!
acs_vars <- c("B08303_001","B25063_001")
myTracts <- c("42101031501","42101031502","42101031501","42101033101","42101033200")
acsTractsPHL.2019.sf <- get_acs(geography = "tract",
year = 2019,
variables = acs_vars,
geometry = TRUE,
state = "PA",
county = "Philadelphia",
output = "wide") %>%
dplyr::select (GEOID, NAME, all_of(paste0(acs_vars,"E"))) %>%
rename (traveltime = B08303_001E, grossrent = B25063_001E) %>%
mutate (Neighborhood = ifelse(GEOID %in% myTracts,
"Mayfair",
"REST OF PHILADELPHIA")) %>%
mutate(grossrent = na_if(grossrent,0))
acsTractsPHL.2019.sf <- acsTractsPHL.2019.sf %>%
st_transform(crs = 4326)