-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAustinLWheat_Lab2.Rmd
87 lines (74 loc) · 2.6 KB
/
AustinLWheat_Lab2.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
---
title: "Lab 2 Assignment"
author: "Austin L. Wheat"
date: "9/12/2021"
output: github_document
editor_options:
markdown:
wrap: sentence
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
```{r setup_package, warning = FALSE, message = FALSE}
library(tidyverse)
library(tidycensus)
library(sf)
library(tmap)
library(viridis)
set.seed(717)
```
## Load data from {tidycensus}
```{r load_variables, cache = TRUE}
vars <- load_variables(2019, "acs5") # Load Census Variables
acs_vars <- c("B15001_050", # Total Female Bachelors
"B15001_009", # Total Male Bachelors
"B01001_001") # ACS total Pop estimate
myTracts <- c("42101000402",
"42101000401",
"42101013602",
"42101013402",
"42101013401",
"42101013601",
"42101000300",
"42101012500",
"42101013300",
"42101013500") # Logan Circle, Fairmount, Spring Garden area
acsTractsPHL.2019.sf <- get_acs(geography = "tract", # Load Census Tracts
year = 2019,
variables = acs_vars,
geometry = TRUE,
state = "PA",
county = "Philadelphia",
output = "wide") %>%
dplyr::select (GEOID, NAME, all_of(paste0(acs_vars, "E"))) %>%
rename (total_FemaleBach.2019 = B15001_050E,
total_MaleBach.2019 = B15001_009E,
total_pop.2019 = B01001_001E) %>%
mutate(pctFemalebach.2019 = ((total_FemaleBach.2019/total_pop.2019)*100), #Do math, get %'s
pctMalebach.2019 = ((total_MaleBach.2019/total_pop.2019)*100)) %>% #Do math, get %'s
mutate(Neighborhood = ifelse(GEOID %in% myTracts,
"Logan Circle",
"REST OF PHILADELPHIA"))
```
## Transform to WGS84 with {sf}
```
acsTractsPHL.2019.sf_WGS84 <- acsTractsPHL.2019.sf %>% #Transform to WFS84
st_transform(crs = "EPSG:4326")
```
## Plot with {ggplot2}
```{r ggplot_geom_sf, warning = FALSE, echo = TRUE}
ggplot()+
geom_sf(data = acsTractsPHL.2019.sf, aes(fill = pctFemalebach.2019),
color = "transparent")+
geom_sf(data = acsTractsPHL.2019.sf %>%
filter(Neighborhood == "Logan Circle") %>%
st_union(),
color = "white",
fill = "transparent") +
labs(
title = "% of Females with a Bachelor's Degree",
subtitle = "Spring Garden Neighborhood Highlighted",
caption = "Philadelphia, PA") +
scale_fill_viridis()
```