#load packages
library (tidycensus)
library (tidyverse)
── Attaching packages ─────────────────────────────────────── tidyverse 1.3.2 ──
✔ ggplot2 3.4.0 ✔ purrr 0.3.4
✔ tibble 3.1.8 ✔ dplyr 1.0.10
✔ tidyr 1.2.0 ✔ stringr 1.4.1
✔ readr 2.1.2 ✔ forcats 0.5.2
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag() masks stats::lag()
Linking to GEOS 3.9.3, GDAL 3.5.2, PROJ 8.2.1; sf_use_s2() is TRUE
library (ggplot2)
library (classInt)
#save API key to working directory
tidycensus:: census_api_key (key = "f23f22ab8d214cd5ce4152926f7fc9f7289da68b" , install = T, 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] "f23f22ab8d214cd5ce4152926f7fc9f7289da68b"
v15_Profile <- load_variables (year = 2019 ,
dataset = "acs5/profile" ,
cache = TRUE )
View (v15_Profile)
v15_Profile%>%
filter (grepl (pattern = "INCOME" , x = label))%>%
select (name, label)
# A tibble: 174 × 2
name label
<chr> <chr>
1 DP03_0051 Estimate!!INCOME AND BENEFITS (IN 2019 INFLATION-ADJUSTED DOLLARS…
2 DP03_0051P Percent!!INCOME AND BENEFITS (IN 2019 INFLATION-ADJUSTED DOLLARS)…
3 DP03_0052 Estimate!!INCOME AND BENEFITS (IN 2019 INFLATION-ADJUSTED DOLLARS…
4 DP03_0052P Percent!!INCOME AND BENEFITS (IN 2019 INFLATION-ADJUSTED DOLLARS)…
5 DP03_0053 Estimate!!INCOME AND BENEFITS (IN 2019 INFLATION-ADJUSTED DOLLARS…
6 DP03_0053P Percent!!INCOME AND BENEFITS (IN 2019 INFLATION-ADJUSTED DOLLARS)…
7 DP03_0054 Estimate!!INCOME AND BENEFITS (IN 2019 INFLATION-ADJUSTED DOLLARS…
8 DP03_0054P Percent!!INCOME AND BENEFITS (IN 2019 INFLATION-ADJUSTED DOLLARS)…
9 DP03_0055 Estimate!!INCOME AND BENEFITS (IN 2019 INFLATION-ADJUSTED DOLLARS…
10 DP03_0055P Percent!!INCOME AND BENEFITS (IN 2019 INFLATION-ADJUSTED DOLLARS)…
# … with 164 more rows
#pull population data and income data
sa_acs<- get_acs (geography = "tract" ,
state= "TX" ,
county = "Bexar" ,
year = 2019 ,
variables= c ("DP05_0001E" , "DP03_0062E" ) ,
geometry = T,
output = "wide" )
Getting data from the 2015-2019 5-year ACS
Downloading feature geometry from the Census website. To cache shapefiles for use in future sessions, set `options(tigris_use_cache = TRUE)`.
Using the ACS Data Profile
|
| | 0%
|
|= | 1%
|
|= | 2%
|
|== | 3%
|
|=== | 4%
|
|=== | 5%
|
|==== | 5%
|
|==== | 6%
|
|===== | 7%
|
|===== | 8%
|
|====== | 8%
|
|====== | 9%
|
|======= | 9%
|
|======= | 10%
|
|======= | 11%
|
|======== | 11%
|
|======== | 12%
|
|========= | 12%
|
|========= | 13%
|
|========= | 14%
|
|========== | 14%
|
|========== | 15%
|
|=========== | 15%
|
|=========== | 16%
|
|============ | 17%
|
|============ | 18%
|
|============= | 18%
|
|============= | 19%
|
|============== | 19%
|
|============== | 20%
|
|============== | 21%
|
|=============== | 21%
|
|=============== | 22%
|
|================ | 22%
|
|================ | 23%
|
|================= | 24%
|
|================= | 25%
|
|================== | 25%
|
|================== | 26%
|
|=================== | 27%
|
|==================== | 28%
|
|==================== | 29%
|
|===================== | 30%
|
|====================== | 32%
|
|======================= | 33%
|
|======================== | 34%
|
|======================== | 35%
|
|========================= | 35%
|
|========================= | 36%
|
|========================== | 37%
|
|========================== | 38%
|
|=========================== | 38%
|
|=========================== | 39%
|
|============================ | 39%
|
|============================ | 40%
|
|============================ | 41%
|
|============================= | 41%
|
|============================= | 42%
|
|============================== | 42%
|
|============================== | 43%
|
|=============================== | 44%
|
|================================ | 45%
|
|================================ | 46%
|
|================================= | 47%
|
|================================== | 48%
|
|================================== | 49%
|
|=================================== | 50%
|
|=================================== | 51%
|
|==================================== | 51%
|
|==================================== | 52%
|
|===================================== | 52%
|
|===================================== | 53%
|
|===================================== | 54%
|
|====================================== | 54%
|
|====================================== | 55%
|
|======================================= | 55%
|
|======================================= | 56%
|
|======================================== | 57%
|
|======================================== | 58%
|
|========================================= | 58%
|
|========================================= | 59%
|
|========================================== | 60%
|
|=========================================== | 61%
|
|=========================================== | 62%
|
|============================================ | 62%
|
|============================================ | 63%
|
|============================================= | 64%
|
|============================================= | 65%
|
|============================================== | 65%
|
|============================================== | 66%
|
|=============================================== | 66%
|
|=============================================== | 67%
|
|=============================================== | 68%
|
|================================================ | 68%
|
|================================================ | 69%
|
|================================================= | 69%
|
|================================================= | 70%
|
|================================================== | 71%
|
|================================================== | 72%
|
|=================================================== | 72%
|
|=================================================== | 73%
|
|==================================================== | 74%
|
|==================================================== | 75%
|
|===================================================== | 75%
|
|===================================================== | 76%
|
|====================================================== | 77%
|
|====================================================== | 78%
|
|======================================================= | 78%
|
|======================================================= | 79%
|
|======================================================== | 79%
|
|======================================================== | 80%
|
|======================================================== | 81%
|
|========================================================= | 81%
|
|========================================================= | 82%
|
|========================================================== | 82%
|
|========================================================== | 83%
|
|=========================================================== | 84%
|
|=========================================================== | 85%
|
|============================================================ | 85%
|
|============================================================ | 86%
|
|============================================================= | 87%
|
|============================================================= | 88%
|
|============================================================== | 88%
|
|============================================================== | 89%
|
|=============================================================== | 90%
|
|=============================================================== | 91%
|
|================================================================ | 91%
|
|================================================================ | 92%
|
|================================================================= | 92%
|
|================================================================= | 93%
|
|================================================================= | 94%
|
|================================================================== | 94%
|
|================================================================== | 95%
|
|=================================================================== | 95%
|
|=================================================================== | 96%
|
|==================================================================== | 97%
|
|==================================================================== | 98%
|
|===================================================================== | 98%
|
|===================================================================== | 99%
|
|======================================================================| 100%
library (tmap)
library (tmaptools)
tm_shape (sa_acs2)+
tm_polygons ("medincome" ,
title= "Median Household Income (in dollars)" ,
palette= "Greens" ,
style= "pretty" , n= 5 )+
tm_format ("World" ,
title= "San Antonio median household Estimates - Pretty Breaks" ,
legend.outside= T)+
tm_scale_bar ()+
tm_compass ()