knitr::opts_chunk$set(echo = TRUE)
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(ggplot2)
library(tidycensus)
ca_msa <- read.csv("C:/Users/anneb/OneDrive - University of Texas at San Antonio/methods1/CA_MSA.csv")
total_population <- ca_msa %>%
group_by(NAME) %>%
summarise(total_population = sum(tpop, na.rm = TRUE))
dissimilarity_index <- ca_msa %>%
group_by(NAME) %>%
summarise(D_index = 0.5 * sum(abs((nhasn / sum(nhasn)) -
(nhwhite / sum(nhwhite))), na.rm = TRUE))
holc <- read.csv("C:/Users/anneb/OneDrive - University of Texas at San Antonio/methods1/holc_census_tracts.csv")
average_holc_area <- holc %>%
group_by(state) %>%
summarise(average_holc_area = mean(holc_area, na.rm = TRUE))
ggplot(holc, aes(x = state, y = holc_area)) +
geom_boxplot() +
labs(title = "HOLC Area Distribution by State", x = "State", y = "HOLC Area")
holc_grade_d_texas <- holc %>%
filter(state == "Texas", holc_grade == "D") %>%
group_by(st_name) %>%
summarise(count_grade_d = n())
vars <- c(poptotal = "B03002_001E", black = "B03002_004E", poverty = "B17017_002E"
)
census_data <- get_acs(geography = "tract",
variables = vars,
state = "TX",
county = "Bexar",
year = 2021,
output = "wide")
## Getting data from the 2017-2021 5-year ACS
census_data1 <- census_data %>%
mutate(
black_pct = black / poptotal * 100,
poverty_pct = poverty / poptotal * 100
)
san_antonio_data <- merge(census_data1, holc, by.x = "GEOID", by.y = "geoid")
black_percentage_by_holc <- san_antonio_data %>%
group_by(holc_grade) %>%
summarise(average_black_percentage = mean(black_pct, na.rm = TRUE))
ggplot(black_percentage_by_holc, aes(x = holc_grade, y = average_black_percentage)) +
geom_bar(stat = "identity", fill = "blue") +
labs(title = "Average Black Percentage by HOLC Grade in San Antonio",
x = "HOLC Grade", y = "Average Black Percentage")
ggplot(san_antonio_data, aes(x = holc_grade, y = holc_area, fill = holc_grade)) +
geom_boxplot() +
labs(title = "HOLC Area in San Antonio by Grade", x = "HOLC Grade", y = "HOLC Area")
This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.
When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
summary(cars)
## speed dist
## Min. : 4.0 Min. : 2.00
## 1st Qu.:12.0 1st Qu.: 26.00
## Median :15.0 Median : 36.00
## Mean :15.4 Mean : 42.98
## 3rd Qu.:19.0 3rd Qu.: 56.00
## Max. :25.0 Max. :120.00
You can also embed plots, for example:
Note that the echo = FALSE
parameter was added to the
code chunk to prevent printing of the R code that generated the
plot.