Introduction

This analysis explores the racial composition of census tracts within New York City’s boroughs, as reported by the Decennial Census. The goal is to understand the distribution of racial groups across the city’s five boroughs: Brooklyn, Queens, Manhattan, The Bronx, and Staten Island.

Calculating and mapping the following variables for each borough:

The results will highlight disparities or patterns of racial distribution across boroughs, providing insights into the city’s diversity.

Check race_data

View(race_data)

Check boros

View(boros)

###Results

# Map for Percent Hispanic or Latino
# tried diffent way to populate still didn't work 

hispanic_map <- ggplot() +
  geom_sf(data = race_data, aes(fill = pct_hispanic), color = "transparent") +
  scale_fill_viridis_c(name = "Percent Hispanic (%)", labels = scales::percent_format(accuracy = 1)) +
  labs(
    title = "Percent Hispanic or Latino by Census Tract",
    subtitle = "New York City, 2020 Decennial Census",
    caption = "Source: 2020 Decennial Census, PL 94-171"
  ) +
  theme_void()

hispanic_map

# Map for Percent Black-alone, not Hispanic or Latino
black_map <- ggplot() +
  geom_sf(data = race_data, aes(fill = pct_black), color = "transparent") +
  scale_fill_distiller(
    palette = "Blues",
    direction = 1,
    name = "Percent Black (%)",
    labels = scales::percent_format(accuracy = 1)) +
  labs(
    title = "Percent Black-alone, Not Hispanic or Latino by Census Tract",
    subtitle = "New York City, 2020 Decennial Census",
    caption = "Source: 2020 Decennial Census, PL 94-171"
  ) +
  theme_void()
print(black_map)

# Map for Percent Asian-alone, not Hispanic or Latino
asian_map <- ggplot() +
  geom_sf(data = race_data, aes(fill = pct_asian), color = "transparent") +
  scale_fill_distiller(
    palette = "Greens",
    direction = 1,
    name = "Percent Asian (%)",
    labels = scales::percent_format(accuracy = 1)
  ) +
  labs(
    title = "Percent Asian-alone, Not Hispanic or Latino by Census Tract",
    subtitle = "New York City, 2020 Decennial Census",
    caption = "Source: 2020 Decennial Census, PL 94-171"
  ) +
  theme_void()
print(asian_map)

# Map for Percent White-alone, not Hispanic or Latino
white_map <- ggplot() +
  geom_sf(data = race_data, aes(fill = pct_white), color = "transparent") +
  scale_fill_distiller(
    palette = "Reds",
    direction = 1,
    name = "Percent White (%)",
    labels = scales::percent_format(accuracy = 1)
  ) +
  labs(
    title = "Percent White-alone, Not Hispanic or Latino by Census Tract",
    subtitle = "New York City, 2020 Decennial Census",
    caption = "Source: 2020 Decennial Census, PL 94-171"
  ) +
  theme_void()
print(white_map)

###summary table by borough

race_summary <- race_data |>
  st_drop_geometry() |> 
  group_by(borough = case_when(
    str_detect(GEOID, "^36") ~ "Bronx",
    str_detect(GEOID, "^29") ~ "Kings",
    str_detect(GEOID, "^10") ~ "New York",
    str_detect(GEOID, "^33") ~ "Queens",
    str_detect(GEOID, "^45") ~ "Richmond"
  )) |> 
  
  summarise(
    `Percent Hispanic` = mean(pct_hispanic, na.rm = TRUE),
    `Percent Black` = mean(pct_black, na.rm = TRUE),
    `Percent Asian` = mean(pct_asian, na.rm = TRUE),
    `Percent White` = mean(pct_white, na.rm = TRUE)
  )

# Display the summary table
print(race_summary)
## # A tibble: 1 × 5
##   borough `Percent Hispanic` `Percent Black` `Percent Asian` `Percent White`
##   <chr>                <dbl>           <dbl>           <dbl>           <dbl>
## 1 Bronx                0.271           0.216           0.155           0.301