Last active
May 19, 2025 03:26
-
-
Save walkerke/b7f22ec87b2eba768877341c98b0ce38 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(mapgl) | |
library(tidycensus) | |
library(tigris) | |
options(tigris_use_cache = TRUE) | |
manhattan_income <- get_acs( | |
geography = "tract", | |
variables = "B19013_001", | |
state = "NY", | |
county = "New York", | |
geometry = TRUE | |
) |> | |
erase_water() | |
manhattan_education <- get_acs( | |
geography = "tract", | |
variables = "DP02_0068P", | |
state = "NY", | |
county = "New York", | |
geometry = TRUE | |
) |> | |
erase_water() | |
manhattan_age <- get_acs( | |
geography = "tract", | |
variables = "B01002_001", | |
state = "NY", | |
county = "New York", | |
geometry = TRUE | |
) |> | |
erase_water() | |
mapboxgl(center = c(-73.9261, 40.8231), | |
zoom = 10, | |
pitch = 67, | |
bearing = -8.3, | |
hash = TRUE) |> | |
add_fill_layer( | |
id = "Median HH income", | |
source = manhattan_income, | |
fill_color = interpolate( | |
"estimate", | |
values = c(11000, 250001), | |
stops = c("lightgreen", "darkgreen"), | |
na_color = "lightgrey" | |
), | |
fill_z_offset = 1000 | |
) |> | |
add_fill_layer( | |
id = "% with college degree", | |
source = manhattan_education, | |
fill_color = interpolate( | |
"estimate", | |
values = c(0, 100), | |
stops = c("lightblue", "darkblue"), | |
na_color = "lightgrey" | |
), | |
fill_z_offset = 4000 | |
) |> | |
add_fill_layer( | |
id = "Median age", | |
source = manhattan_age, | |
fill_color = interpolate( | |
"estimate", | |
values = c(20, 68), | |
stops = c("lightpink", "maroon"), | |
na_color = "lightgrey" | |
), | |
fill_z_offset = 7000 | |
) |> | |
add_layers_control() |> | |
add_legend( | |
"Median income", | |
values = c("$11k", "$250k"), | |
colors = c("lightgreen", "darkgreen"), | |
position = "bottom-left" | |
) |> | |
add_legend( | |
"% with college degree", | |
values = c("0%", "100%"), | |
colors = c("lightblue", "darkblue"), | |
position = "top-right", | |
add = TRUE | |
) |> | |
add_legend( | |
"Median age", | |
values = c("20", "68"), | |
colors = c("lightpink", "maroon"), | |
position = "bottom-right", | |
add = TRUE | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment