# NOT RUN {
# Wrapped in \donttest{} because all these examples take >5 seconds
# and require a Census API key.
# ADI of all census tracts in Cuyahoga County, Ohio
get_adi(geography = "tract", state = "OH", county = "Cuyahoga")
# ADI of all counties in Connecticut, using the 2014 ACS1 survey.
# Returns a warning because there are only 8 counties.
# A minimum of 30 locations is recommended.
get_adi(geography = "county", state = "CT", year = 2014, dataset = "acs1")
# Areas with zero households will have an ADI of NA:
queens <-
get_adi(
"tract",
state = "NY",
county = "Queens",
keep_indicators = TRUE,
geometry = TRUE
)
queens %>%
dplyr::as_tibble() %>%
dplyr::select(GEOID, NAME, ADI, households = B11005_001) %>%
dplyr::filter(is.na(ADI) | households == 0) %>%
print(n = Inf)
# geoid argument allows for highly customized reference populations.
# ADI of all census tracts in the GEOIDs stored in "delmarva" below:
# Notice the mixing of state- ("10") and county-level GEOIDs (the others).
delmarva_geoids <- c("10", "51001", "51131", "24015", "24029", "24035",
"24011", "24041", "24019", "24045", "24039", "24047")
delmarva <-
get_adi(
geography = "tract",
geoid = delmarva_geoids,
dataset = "decennial",
year = 2000,
geometry = TRUE
)
# Demonstration of geom_sf() integration:
require(ggplot2)
# The na.value argument changes the fill of NA ADI areas.
delmarva %>% ggplot() + geom_sf(aes(fill = ADI), lwd = 0)
# Setting direction = -1 makes the less deprived areas the lighter ones
# The argument na.value changes the color of zero-household areas
queens %>%
ggplot() +
geom_sf(aes(fill = ADI), lwd = 0) +
scale_fill_viridis_c(na.value = "red", direction = -1)
# Obtain factor loadings:
attr(queens, "loadings")
# }
Run the code above in your browser using DataLab