#' @title Make The Vulnerability Indicators
#' @description Temporary description.
#' @param acs_indicators Tibble, Temporary description.
#' @return a `tibble`
#' @export
make_vulnerability_indicators <- function(acs_indicators){
get_greater_vars <- function(data){
# For each tract, returns each INDICATOR name (e.g., RACE, TENURE, etc.)
# where the proportion of the tract is greater than the county
if(sum(data$N) ==0){return("none")}
data %>% dplyr::filter(N>0) %>% purrr::pluck("INDICATOR")
}
vuln_inds <- acs_indicators %>%
dplyr::group_by(GEOID, ENDYEAR, INDICATOR) %>%
dplyr::summarise(N = sum(as.numeric(GREATER_THAN_COUNTY), na.rm = TRUE)) %>%
tidyr::nest() %>%
dplyr::mutate(N = purrr::map_dbl(data, ~ purrr::pluck(.x,"N") %>% sum),
VULNERABLE_LGL = N > 2,
VULNERABLE_INDS = purrr::map_chr(data, ~ get_greater_vars(.x) %>% stringr::str_c(collapse = ", "))) %>%
dplyr::filter(ENDYEAR %in% 2016) %>%
dplyr::transmute(GEOID, VULNERABLE_TR_CNT = N, VULNERABLE_LGL, VULNERABLE_INDS)
vulnerability_indicators <- vuln_inds
return(vulnerability_indicators)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.