library(tidyverse)
library(tidycensus)
library(sf)
library(scales)
library(viridis)
library(knitr)
library(RColorBrewer)
library(knitr)
library(plotly)
Borough boundaries are represented with a shapefile that was downloaded from NYC Open Data.
Census tract boundaries and data are from the 2016-2020 5-year American Community Survey, accessed with the tidyverse R package. Census data includes:
The proportion of people with West Indian ancestry for each census tract was calculated and the census tracts with no residents were removed.
acs201620 <- load_variables(2020, "acs5", cache = T)
raw_ancestry <- suppressWarnings(get_acs(geography = "tract",
variables = c(ancestry_pop = "B04006_001",
west_indian = "B04006_094"),
state='NY',
county = 'Kings',
geometry = T,
year = 2020,
output = "wide"))
west_indian <- raw_ancestry |>
mutate(pct_west_indian = west_indianE/ancestry_popE)
na_tracts <- west_indian |>
filter(is.na(pct_west_indian))
west_indian <- raw_ancestry |>
mutate(pct_west_indian = west_indianE/ancestry_popE,
pct_west_indian = ifelse(is.nan(pct_west_indian), NA, pct_west_indian)) |>
filter(ancestry_popE>0)
boros <- st_read("data/raw/geo/Borough Boundaries.geojson")
nabes <- st_read("data/raw/geo/nynta2020.shp")
west_indian_map <-ggplot() +
suppressWarnings(geom_sf(
data = west_indian, mapping = aes(fill = pct_west_indian,
text = paste0(NAME, ":",
"<br>Percent West Indian ancestry: ",
percent(pct_west_indian, accuracy=1))),
color = "transparent")) +
# lwd = 0) + # removes the census tract outline
theme_void() +
scale_fill_distiller(breaks=c(0, .2, .4, .6, .8, 1),
direction = 1,
na.value = "transparent",
name="Percent West Indian Ancestry (%)",
labels=percent_format(accuracy = 1L)) +
labs(
title = "Brooklyn, West Indian Ancestry by Census Tract",
caption = "Source: American Community Survey, 2016-20"
) +
suppressWarnings(geom_sf(data = nabes |> filter(BoroName == "Brooklyn"),
color = "gray", fill = NA, lwd = 0.25)) +
suppressWarnings(geom_sf(data = boros |> filter(boro_name=="Brooklyn"), color = "black", fill = NA, lwd = .5))
ggplotly(west_indian_map, tooltip="text")
As you can see from the map above the population with largest percentage of people with West Indian ancestry are located in central and east Brooklyn.