Homework2_Median Household Income

Author

Julie Gonzalez

Median Household Income (DP03-0062E)

library(tidycensus)
library(tidyverse)
── Attaching packages ─────────────────────────────────────── tidyverse 1.3.2 ──
✔ ggplot2 3.4.0      ✔ purrr   1.0.1 
✔ tibble  3.1.8      ✔ dplyr   1.0.10
✔ tidyr   1.3.0      ✔ stringr 1.5.0 
✔ readr   2.1.3      ✔ forcats 0.5.2 
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag()    masks stats::lag()
library(sf)
Linking to GEOS 3.11.0, GDAL 3.5.3, PROJ 9.1.0; sf_use_s2() is TRUE
library(ggplot2)
library(classInt)
v15_Profile <- load_variables(year = 2019 ,
dataset = "acs5/profile",
cache = TRUE)
 #View(v15_Profile)
 
 v15_Profile%>%
filter(grepl(pattern = "Median", x = label))%>%
select(name, label)
# A tibble: 24 × 2
   name       label                                                             
   <chr>      <chr>                                                             
 1 DP03_0062  Estimate!!INCOME AND BENEFITS (IN 2019 INFLATION-ADJUSTED DOLLARS…
 2 DP03_0062P Percent!!INCOME AND BENEFITS (IN 2019 INFLATION-ADJUSTED DOLLARS)…
 3 DP03_0086  Estimate!!INCOME AND BENEFITS (IN 2019 INFLATION-ADJUSTED DOLLARS…
 4 DP03_0086P Percent!!INCOME AND BENEFITS (IN 2019 INFLATION-ADJUSTED DOLLARS)…
 5 DP03_0090  Estimate!!INCOME AND BENEFITS (IN 2019 INFLATION-ADJUSTED DOLLARS…
 6 DP03_0090P Percent!!INCOME AND BENEFITS (IN 2019 INFLATION-ADJUSTED DOLLARS)…
 7 DP03_0092  Estimate!!INCOME AND BENEFITS (IN 2019 INFLATION-ADJUSTED DOLLARS…
 8 DP03_0092P Percent!!INCOME AND BENEFITS (IN 2019 INFLATION-ADJUSTED DOLLARS)…
 9 DP03_0093  Estimate!!INCOME AND BENEFITS (IN 2019 INFLATION-ADJUSTED DOLLARS…
10 DP03_0093P Percent!!INCOME AND BENEFITS (IN 2019 INFLATION-ADJUSTED DOLLARS)…
# … with 14 more rows
#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
Warning: • You have not set a Census API key. Users without a key are limited to 500
queries per day and may experience performance limitations.
ℹ For best results, get a Census API key at
http://api.census.gov/data/key_signup.html and then supply the key to the
`census_api_key()` function to use it throughout your tidycensus session.
This warning is displayed once per session.
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
# 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,
         medincome=DP03_0062E) %>%
  st_transform(crs = 2919)%>%
  na.omit()
library(tmap)
library(tmaptools)

tm_shape(sa_acs2) +
  tm_polygons("medincome",
              title="Median Household Income",
              palette="Purples",
              style="pretty", n=7 )+
  tm_format("World",
            title="San Antonio Median Household Estimates - Pretty Breaks", 
            legend.outside=T,
            text.size=100)+
  tm_scale_bar()+
  tm_compass()