library(tidycensus)
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.4 ✔ readr 2.1.5
## ✔ forcats 1.0.0 ✔ stringr 1.5.1
## ✔ ggplot2 3.5.1 ✔ tibble 3.2.1
## ✔ lubridate 1.9.3 ✔ tidyr 1.3.1
## ✔ purrr 1.0.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
census_api_key("a613904e39830d89c16a19999e1cfaead6422fd1", install = TRUE, overwrite = TRUE)
## Your original .Renviron will be backed up and stored in your R HOME directory if needed.
## Your API key has been stored in your .Renviron and can be accessed by Sys.getenv("CENSUS_API_KEY").
## To use now, restart R or run `readRenviron("~/.Renviron")`
## [1] "a613904e39830d89c16a19999e1cfaead6422fd1"
v22 <-load_variables(2022, "acs5", cache = TRUE)
v22
## # A tibble: 28,152 × 4
## name label concept geography
## <chr> <chr> <chr> <chr>
## 1 B01001A_001 Estimate!!Total: Sex by Age (W… tract
## 2 B01001A_002 Estimate!!Total:!!Male: Sex by Age (W… tract
## 3 B01001A_003 Estimate!!Total:!!Male:!!Under 5 years Sex by Age (W… tract
## 4 B01001A_004 Estimate!!Total:!!Male:!!5 to 9 years Sex by Age (W… tract
## 5 B01001A_005 Estimate!!Total:!!Male:!!10 to 14 years Sex by Age (W… tract
## 6 B01001A_006 Estimate!!Total:!!Male:!!15 to 17 years Sex by Age (W… tract
## 7 B01001A_007 Estimate!!Total:!!Male:!!18 and 19 years Sex by Age (W… tract
## 8 B01001A_008 Estimate!!Total:!!Male:!!20 to 24 years Sex by Age (W… tract
## 9 B01001A_009 Estimate!!Total:!!Male:!!25 to 29 years Sex by Age (W… tract
## 10 B01001A_010 Estimate!!Total:!!Male:!!30 to 34 years Sex by Age (W… tract
## # ℹ 28,142 more rows
write.csv(v22,"C:/Users/khori/OneDrive/POS4931/v22.csv")
f1 <- get_acs(geography = "county",
variables = c(naturalized_citzn = "B05001_005", naturalized_asia = "B05002_016"),
state = "FL",
geometry = T,
year = 2022)
f1_wider <- f1 |>
select(-moe) |>
pivot_wider(names_from = variable, values_from = estimate) |>
mutate(asia_naturalized_pct = naturalized_asia/naturalized_citzn)
f1_wider |>
ggplot(aes(fill = asia_naturalized_pct)) +
geom_sf(color = "white")

scale_fill_viridis_c(option = "cividis")
## <ScaleContinuous>
## Range:
## Limits: 0 -- 1