library(tidycensus)
library(tidyr)
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)
census_api_key('26c91fd986e86c89e61cf1f5d94ccd109067a935')
## To install your API key for use in future sessions, run this function with `install = TRUE`.
fl_data<- get_acs(geography = 'county', variables = c(total_pop="B01003_001", white = "B02001_002", hispanic_pop = "B03003_003"), state = "FL", geometry = T, year = 2022)
## Getting data from the 2018-2022 5-year ACS
## Downloading feature geometry from the Census website.  To cache shapefiles for use in future sessions, set `options(tigris_use_cache = TRUE)`.
##   |                                                                              |                                                                      |   0%  |                                                                              |                                                                      |   1%  |                                                                              |=                                                                     |   1%  |                                                                              |=                                                                     |   2%  |                                                                              |==                                                                    |   2%  |                                                                              |==                                                                    |   3%  |                                                                              |====                                                                  |   6%  |                                                                              |=====                                                                 |   7%  |                                                                              |=====                                                                 |   8%  |                                                                              |======                                                                |   8%  |                                                                              |======                                                                |   9%  |                                                                              |=======                                                               |  10%  |                                                                              |========                                                              |  12%  |                                                                              |==========                                                            |  15%  |                                                                              |===========                                                           |  15%  |                                                                              |=============                                                         |  18%  |                                                                              |=============                                                         |  19%  |                                                                              |================                                                      |  23%  |                                                                              |====================                                                  |  28%  |                                                                              |====================                                                  |  29%  |                                                                              |========================                                              |  34%  |                                                                              |========================                                              |  35%  |                                                                              |============================                                          |  39%  |                                                                              |===============================                                       |  44%  |                                                                              |===============================                                       |  45%  |                                                                              |================================                                      |  45%  |                                                                              |================================                                      |  46%  |                                                                              |=================================                                     |  47%  |                                                                              |=====================================                                 |  53%  |                                                                              |======================================                                |  54%  |                                                                              |========================================                              |  57%  |                                                                              |===========================================                           |  61%  |                                                                              |============================================                          |  63%  |                                                                              |=============================================                         |  65%  |                                                                              |==============================================                        |  66%  |                                                                              |================================================                      |  68%  |                                                                              |=================================================                     |  71%  |                                                                              |====================================================                  |  75%  |                                                                              |======================================================                |  78%  |                                                                              |========================================================              |  79%  |                                                                              |=========================================================             |  81%  |                                                                              |==========================================================            |  83%  |                                                                              |=============================================================         |  87%  |                                                                              |===============================================================       |  89%  |                                                                              |===============================================================       |  90%  |                                                                              |=================================================================     |  92%  |                                                                              |======================================================================| 100%
fl_data <- fl_data |>
  select(-moe)|>
  pivot_wider(names_from = variable, values_from = estimate)|>
  mutate(whitepct = (white / total_pop) * 100

  )
library(dplyr)

fl_data <- fl_data %>%
  mutate(percent_hispanic = (hispanic_pop/total_pop)) %>%
  filter(!is.na(percent_hispanic))
library(sf)
## Linking to GEOS 3.11.0, GDAL 3.5.3, PROJ 9.1.0; sf_use_s2() is TRUE
fl_data <- fl_data %>% 
  filter(!is.na(percent_hispanic)) %>%
  st_as_sf() 
ggplot(data = fl_data) +
  geom_sf(aes(fill = percent_hispanic)) +
  scale_fill_viridis_c(option = "plasma", name = "% Hispanic") +
  theme_minimal() +
  labs(
    title = "Percent Hispanic Population in Florida by County",
    subtitle = "2018-2022 American Community Survey",
    caption = "Source: U.S. Census Bureau"
  )