v15_Profile <- load_variables(year = 2019 ,
dataset = "acs5/profile",
cache = TRUE)
v15_Profile%>%
filter(grepl(pattern = "DOLLARS)!!Median", x = label))%>%
select(name, label)
## # A tibble: 6 × 2
## name label
## <chr> <chr>
## 1 DP03_0092 Estimate!!INCOME AND BENEFITS (IN 2019 INFLATION-ADJUSTED DOLLARS)…
## 2 DP03_0092P Percent!!INCOME AND BENEFITS (IN 2019 INFLATION-ADJUSTED DOLLARS)!…
## 3 DP03_0093 Estimate!!INCOME AND BENEFITS (IN 2019 INFLATION-ADJUSTED DOLLARS)…
## 4 DP03_0093P Percent!!INCOME AND BENEFITS (IN 2019 INFLATION-ADJUSTED DOLLARS)!…
## 5 DP03_0094 Estimate!!INCOME AND BENEFITS (IN 2019 INFLATION-ADJUSTED DOLLARS)…
## 6 DP03_0094P Percent!!INCOME AND BENEFITS (IN 2019 INFLATION-ADJUSTED DOLLARS)!…
v15_Profile%>%
filter(grepl(pattern = "Built 2000 to 2009", x = label))%>%
select(name, label)
## # A tibble: 2 × 2
## name label
## <chr> <chr>
## 1 DP04_0019 Estimate!!YEAR STRUCTURE BUILT!!Total housing units!!Built 2000 to…
## 2 DP04_0019P Percent!!YEAR STRUCTURE BUILT!!Total housing units!!Built 2000 to …
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%
|
|== | 2%
|
|== | 3%
|
|=== | 4%
|
|=== | 5%
|
|==== | 5%
|
|==== | 6%
|
|===== | 7%
|
|===== | 8%
|
|====== | 8%
|
|====== | 9%
|
|======= | 10%
|
|======= | 11%
|
|======== | 11%
|
|======== | 12%
|
|========= | 12%
|
|========= | 13%
|
|========= | 14%
|
|========== | 14%
|
|========== | 15%
|
|=========== | 16%
|
|============ | 17%
|
|============ | 18%
|
|============= | 18%
|
|============= | 19%
|
|============== | 19%
|
|============== | 20%
|
|============== | 21%
|
|=============== | 21%
|
|=============== | 22%
|
|================ | 22%
|
|================ | 23%
|
|================= | 24%
|
|================= | 25%
|
|================== | 26%
|
|=================== | 27%
|
|==================== | 28%
|
|==================== | 29%
|
|===================== | 30%
|
|====================== | 31%
|
|====================== | 32%
|
|======================= | 33%
|
|======================== | 34%
|
|======================== | 35%
|
|========================= | 35%
|
|========================= | 36%
|
|========================== | 37%
|
|========================== | 38%
|
|=========================== | 38%
|
|=========================== | 39%
|
|============================ | 39%
|
|============================ | 40%
|
|============================ | 41%
|
|============================= | 41%
|
|============================= | 42%
|
|============================== | 43%
|
|=============================== | 44%
|
|=============================== | 45%
|
|================================ | 45%
|
|================================ | 46%
|
|================================= | 47%
|
|================================= | 48%
|
|================================== | 48%
|
|================================== | 49%
|
|=================================== | 50%
|
|=================================== | 51%
|
|==================================== | 51%
|
|==================================== | 52%
|
|===================================== | 52%
|
|===================================== | 53%
|
|====================================== | 54%
|
|====================================== | 55%
|
|======================================= | 55%
|
|======================================= | 56%
|
|======================================== | 57%
|
|======================================== | 58%
|
|========================================= | 58%
|
|========================================= | 59%
|
|========================================== | 60%
|
|=========================================== | 61%
|
|=========================================== | 62%
|
|============================================ | 62%
|
|============================================ | 63%
|
|============================================= | 64%
|
|============================================= | 65%
|
|============================================== | 65%
|
|============================================== | 66%
|
|=============================================== | 66%
|
|=============================================== | 67%
|
|=============================================== | 68%
|
|================================================ | 68%
|
|================================================ | 69%
|
|================================================= | 70%
|
|================================================= | 71%
|
|================================================== | 71%
|
|================================================== | 72%
|
|=================================================== | 72%
|
|=================================================== | 73%
|
|==================================================== | 74%
|
|==================================================== | 75%
|
|===================================================== | 75%
|
|===================================================== | 76%
|
|====================================================== | 77%
|
|====================================================== | 78%
|
|======================================================= | 78%
|
|======================================================= | 79%
|
|======================================================== | 79%
|
|======================================================== | 80%
|
|========================================================= | 81%
|
|========================================================= | 82%
|
|========================================================== | 82%
|
|========================================================== | 83%
|
|=========================================================== | 84%
|
|=========================================================== | 85%
|
|============================================================ | 85%
|
|============================================================ | 86%
|
|============================================================= | 87%
|
|============================================================= | 88%
|
|============================================================== | 88%
|
|============================================================== | 89%
|
|=============================================================== | 90%
|
|================================================================ | 91%
|
|================================================================ | 92%
|
|================================================================= | 92%
|
|================================================================= | 93%
|
|================================================================= | 94%
|
|================================================================== | 94%
|
|================================================================== | 95%
|
|=================================================================== | 95%
|
|=================================================================== | 96%
|
|==================================================================== | 97%
|
|===================================================================== | 98%
|
|===================================================================== | 99%
|
|======================================================================| 100%
## Data Extraction and Variable
head(sa_acs)
## Simple feature collection with 6 features and 6 fields
## Geometry type: MULTIPOLYGON
## Dimension: XY
## Bounding box: xmin: -98.56606 ymin: 29.36662 xmax: -98.44832 ymax: 29.54044
## Geodetic CRS: NAD83
## GEOID NAME DP05_0001E DP05_0001M
## 1 48029190601 Census Tract 1906.01, Bexar County, Texas 4514 788
## 2 48029181100 Census Tract 1811, Bexar County, Texas 6359 523
## 3 48029140700 Census Tract 1407, Bexar County, Texas 4838 303
## 4 48029180602 Census Tract 1806.02, Bexar County, Texas 3751 536
## 5 48029140800 Census Tract 1408, Bexar County, Texas 5124 453
## 6 48029170200 Census Tract 1702, Bexar County, Texas 5599 617
## DP03_0062E DP03_0062M geometry
## 1 46818 14436 MULTIPOLYGON (((-98.52602 2...
## 2 64930 6521 MULTIPOLYGON (((-98.56225 2...
## 3 36222 6656 MULTIPOLYGON (((-98.47348 2...
## 4 38389 7038 MULTIPOLYGON (((-98.56606 2...
## 5 43299 3656 MULTIPOLYGON (((-98.4778 29...
## 6 25755 7141 MULTIPOLYGON (((-98.5283 29...
# create a county FIPS code - 5 digit
sa_acs$county<-substr(sa_acs$GEOID, 1, 5)
# rename variables and filter missing cases
sa_acs2<-sa_acs%>%
mutate(totpop= DP05_0001E,
med_hh_inc=DP03_0062E) %>%
st_transform(crs = 2019)%>%
na.omit()
library(tmap)
library(tmaptools)
tm_shape(sa_acs2)+
tm_polygons("med_hh_inc",
title="Median Household Income",
palette="Greens",
style="pretty", n=5)+
tm_format("World",
title="Author: Joshua Reyna",
legend.outside=T)+
tm_layout(main.title="Bexar County Median Income Estimatres:Pretty Breaks",
main.title.position = "center")+
tm_scale_bar()+
tm_compass()
ggsave(filename="C:/Users/josha/Desktop/Fall 2020 Stats 1 Dem/lab1map1.png",
dpi = "print")
## Saving 7 x 5 in image