This code’s function is to grab the ACS data needed to create the graph.
The code starts by searching the Census data by state (Florida) and county.
The 5rd line of code specifies the two variables called from the American Community Survey Data (Total Population and Black Population).
florida <-
get_acs(
state = "FL",
geography = "county",
variables = c(tot_pop = "B01003_001", black = "B02001_003"),
geometry = TRUE,
year = 2022
)
## Getting data from the 2018-2022 5-year ACS
This set of code create a separate dataset titled florida_wider.
This pipe starts off by getting rid of the Margin of Error columns to avoid any potential errors.
Another column is then created to house black_pct, a percentage calculated by dividing the Black population by county by the entire county’s population.
florida_wider <- florida |>
select(-moe) |>
pivot_wider(names_from = variable, values_from = estimate) |>
mutate(black_pct = black/tot_pop)
This set of code utilizes ggplot, a package built into tidyverse, in order to create a visualization of the data gathered.
The counties are filled according to the percentage of Black individuals located in the county compared to the county’s population.
The color scheme magma was originally used, but was changed to plasma to better see the abnormal counties.
florida_wider |>
ggplot(aes(fill = black_pct)) +
geom_sf(color = NA) +
scale_fill_viridis_c(option = "plasma")