Mapping the portion of people with West Indian ancestry in Brooklyn
library(tidyverse)
library(tidycensus)
library(sf)
library(scales)
library(RColorBrewer)
library(plotly)
## Warning: package 'plotly' was built under R version 4.3.2
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 number of people with West Indian ancestry total population that reports ancestry The proportion of people with West Indian ancestry for each census tract was calculated and the census tracts with no residents were removed.
boros <- st_read("C:/Users/leah/Desktop/DUE/SEM 1/METHODS/class_data/methods1/part2/data/raw/Geo/Borough Boundaries.geojson")
raw_ancestry <- get_acs(geography = "tract",
variables = c(ancestry_pop = "B04006_001",
west_indian = "B04006_094"),
state='NY',
county = 'Kings',
geometry = T,
year = 2020,
output = "wide")
## 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.
west_indian <- raw_ancestry |>
mutate(pct_west_indian = west_indianE/ancestry_popE) |>
filter(ancestry_popE > 0)
west_indian_map <- ggplot() +
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") +
theme_void() +
scale_fill_distiller(breaks=c(0, .2, .4, .6, .8, 1),
direction = 1,
na.value = "#fafafa",
# 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"
) +
geom_sf(data = boros |> filter(boro_name == "Brooklyn"),
color = "black", fill = NA, lwd = .5)
## Warning in layer_sf(geom = GeomSf, data = data, mapping = mapping, stat = stat,
## : Ignoring unknown aesthetics: text
ggplotly(west_indian_map, tooltip = "text")
From the data “Canarsie” seems to have the highest percentage of people having West Indian ancestry in brooklyn
nabes <- st_read("C:/Users/leah/Desktop/DUE/SEM 1/METHODS/class_data/methods1/part2/data/raw/Geo/nynta2020_23c/nynta2020.shp")
west_indian_2263 <- st_transform(west_indian, 2263)
st_crs(west_indian_2263)
nabes_selected <- nabes |>
select(BoroCode, BoroName, NTA2020, NTAName)
Joining data to create a data frame for Canarsie
west_indian_nabes <- west_indian_2263 |>
st_join(nabes_selected,
left = TRUE,
join = st_intersects,
largest = TRUE)
## Warning: attribute variables are assumed to be spatially constant throughout
## all geometries
Canarsie
ggplot(data = west_indian_nabes |>
filter(NTAName == "Canarsie"),
mapping = aes(fill = pct_west_indian)) +
geom_sf(color = "#ffffff",
lwd = 0) +
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 = "Canarsie, Brooklyn , West Indian Ancestry by Census Tract",
caption = "Source: American Community Survey, 2016-20"
) +
geom_sf(data = nabes |> filter(NTAName == "Canarsie"),
color = "black", fill = NA, lwd = 0.5)