I Used the Hispanic population and the totl population to get the % hispanic population in florida at the county level.
# Retrieve county-level data for Florida
florida_data <- get_acs(
geography = "county", # County-level data
variables = c(total_pop = "B01003_001", hispanic_pop = "B03002_012"),
state = "FL", # Florida state code
year = 2022, # ACS 2022 data
geometry = TRUE # Include geographic data for mapping
)
# Reshape the data using pivot_wider and mutate into percent Hispanic
florida_data_wide <- florida_data |>
pivot_wider(names_from = variable, values_from = estimate) |>
mutate(percent_hispanic = (hispanic_pop / total_pop) * 100) |>
select(-moe)
# Check new data
head(florida_data_wide)
# Save CSV file
write.csv(florida_data_wide, "florida_hispanic_population.csv", row.names = FALSE)
# map of Hispanic population percentage
ggplot(data = florida_data_wide) +
geom_sf(aes(fill = percent_hispanic), color = "white") +
scale_fill_viridis_c(option = "plasma", name = "% Hispanic") +
labs(
title = "Percentage of Hispanic Population in Florida Counties (2022 ACS)",
caption = "Source: U.S. Census Bureau, American Community Survey 2022"
) +
theme_minimal()