library(tidycensus)
library(tidyverse)
## -- Attaching packages --------------------------------------- tidyverse 1.3.1 --
## v ggplot2 3.3.5 v purrr 0.3.4
## v tibble 3.2.1 v dplyr 1.1.2
## v tidyr 1.2.0 v stringr 1.4.0
## v readr 2.1.2 v forcats 0.5.1
## Warning: package 'tibble' was built under R version 4.1.3
## Warning: package 'dplyr' was built under R version 4.1.3
## -- Conflicts ------------------------------------------ tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
library(sf)
## Warning: package 'sf' was built under R version 4.1.3
## Linking to GEOS 3.10.2, GDAL 3.4.1, PROJ 7.2.1; sf_use_s2() is TRUE
census_api_key("aaa228e30415ffb45f165fec08900614d61bebcf")
## To install your API key for use in future sessions, run this function with `install = TRUE`.
total_pop_2021 <- get_acs(geography = "county",
state = "FL",
variables = "B03002_001",
year = 2021) %>%
select(GEOID, estimate) %>%
rename(total_pop_2021 = estimate) %>%
rename(GEOID20 = GEOID)
## Getting data from the 2017-2021 5-year ACS
fl_counties <- st_read("C:/Users/Kendall/Downloads/tl_2020_12_county20/tl_2020_12_county20.shp")
## Reading layer `tl_2020_12_county20' from data source
## `C:\Users\Kendall\Downloads\tl_2020_12_county20\tl_2020_12_county20.shp'
## using driver `ESRI Shapefile'
## Simple feature collection with 67 features and 17 fields
## Geometry type: MULTIPOLYGON
## Dimension: XY
## Bounding box: xmin: -87.6349 ymin: 24.39631 xmax: -79.97431 ymax: 31.00097
## Geodetic CRS: NAD83
fl_counties <- inner_join(fl_counties, total_pop_2021, by = "GEOID20")
ggplot(fl_counties) +
geom_sf(aes(fill = total_pop_2021)) +
scale_fill_gradient(low = "lightblue", high = "darkblue") +
ggtitle("Total population") +
theme_minimal()
