Skip to content

Commit

Permalink
update CFC location maps
Browse files Browse the repository at this point in the history
  • Loading branch information
amd112 committed May 29, 2024
1 parent 747435a commit 315eef8
Show file tree
Hide file tree
Showing 41 changed files with 39,295 additions and 66 deletions.
101 changes: 35 additions & 66 deletions code/04_create_apr2024_cfc_map.R
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,10 @@ mapview::mapshot(map,
################################################################################

# prep for plotting
quantile(ntas$cfc_count)
pal = councildown::colorBin(
palette = "cool",
bins = c(0.00001, 1, 2, 4, 6, 15),
bins = c(-0.01, 0.00001, 1, 2, 4, 6, 15),
domain = ntas$cfc_count,
na.color = "lightgrey"
)
Expand All @@ -153,103 +154,71 @@ pal = councildown::colorBin(
# plot
map = leaflet() %>%
addPolygons(data = ntas, weight = 0, color = ~pal(cfc_count),
fillOpacity = 1, smoothFactor = 0) %>%
fillOpacity = 1, smoothFactor = 0,
popup = ~paste0("<strong>CFC locations:</strong> ", cfc_count, "<br>",
"<strong>Total population:</strong> ", round(population, 0))) %>%
addCouncilStyle(add_dists = T,
highlight_dists = c(7, 9, 27, 28, 36, 40, 41, 42, 45)) %>%
addSourceText("Source: NYC Open Data, NYC Human Resources Administration") %>%
addLegend_decreasing(position = "topleft", pal = pal, values = c(ntas$cfc_count, NA),
addLegend_decreasing(position = "topleft", #pal = pal,
colors = rev(c("#e3eaf7", "#a5adcd", "#8691b9", "#6775a5", "#485a91", "#23417d")),
na.label = "no CFC locations",
title = "# of CFC locations by NTA",
opacity = 1, decreasing = T)
labels = rev(c("0", "1", "2", "3 - 4", "5 - 6", "7 - 13")),
opacity = 1, decreasing = F)

mapview::mapshot(map,
file = file.path("visuals", "number_CFC_locations.pdf"),
remove_controls = c("homeButton", "layersControl", "zoomControl"),
vwidth = 1000, vheight = 850)
saveWidget(map, file=file.path('visuals', "number_CFC_locations.html"))


################################################################################
# plot static map - NTAs w high FI pop + low CFC locations
################################################################################

quantile(ntas$cfc_per10k_fi[ntas$ins_pop > 7000], c(0.33, 0.66), na.rm=T)

ntas = ntas %>%
mutate(ins_pop = round(population*food_insecurity_2023, 0),
category = case_when(ins_pop > 7000 & cfc_per10k_fi <= 2.4 ~ "many food insecure people, low support",
ins_pop > 7000 & cfc_per10k_fi > 2.4 & cfc_per10k_fi <= 4.7 ~ "many food insecure people, mid support",
ins_pop > 7000 & cfc_per10k_fi > 4.7 ~ "many food insecure people, high support",
T ~ "other"),
category = factor(category, levels = c("many food insecure people, low support",
"many food insecure people, mid support",
"many food insecure people, high support",
"other")))

pal = colorFactor(
palette = c("#70B3EF", "#1f3a70", "#1d5fd6", "lightgrey"),
domain = levels(ntas$category),
na.color = "grey"
)

# plot
map = leaflet() %>%
addPolygons(data = ntas, weight = 0, color = ~pal(category),
fillOpacity = 1, smoothFactor = 0) %>%
addPolygons(data = parks, color = "grey", fillColor = "grey", weight = 0,
fillOpacity = 1, smoothFactor = 0) %>%
addCouncilStyle(add_dists = T,
highlight_dists = c(43, 20, 15, 18, 8, 10, 14, 25, 34, 48)) %>%
addSourceText("Source: NYC Open Data") %>%
addLegend_decreasing(position = "topleft", pal = pal,
values = unique(ntas$category),
title = paste0("High Food Insecurity Areas<br>",
"'many food insecure people' means > 7k people<br>",
"'high support' means > 5 CFC locations per 10k people<br>",
"'low support' means < 2 CFC locations per 10k people"),
opacity = 1, decreasing = T)

mapview::mapshot(map,
file = file.path("visuals", "CFC_locations_support.pdf"),
remove_controls = c("homeButton", "layersControl", "zoomControl"),
vwidth = 1000, vheight = 850)


################################################################################
# plot static map - NTAs w high FI pop + low CFC locations - SIMPLE
################################################################################

summary(ntas$ins_pop)
summary(ntas$cfc_per10k_fi[ntas$ins_pop > 6223], na.rm=T)
fi_pop = mean(ntas$ins_pop, na.rm=T)
cfc_temp = mean(ntas$cfc_per10k_fi, na.rm=T)

ntas = ntas %>%
mutate(ins_pop = round(population*food_insecurity_2023, 0),
category = case_when(ins_pop > 6223 & cfc_per10k_fi <= 3.936 ~ "above average # of food insecure people, below average # of cfc locations",
ins_pop > 6223 & cfc_per10k_fi > 3.936 ~ "above average # of food insecure people, above average # of cfc locations",
T ~ "below average # of food insecure people"),
category = factor(category, levels = c("above average # of food insecure people, below average # of cfc locations",
"above average # of food insecure people, above average # of cfc locations",
"below average # of food insecure people")))

pal = colorFactor(
palette = c("#A1CBF1", "#1f3a70", "lightgrey"),
mutate(category = case_when(ins_pop > fi_pop & cfc_per10k_fi <= cfc_temp ~ "ABOVE average # of food insecure people, BELOW average CFC access",
ins_pop > fi_pop & cfc_per10k_fi > cfc_temp ~ "ABOVE average # of food insecure people, ABOVE average CFC access",
ins_pop <= fi_pop & cfc_per10k_fi <= cfc_temp ~ "BELOW average # of food insecure people, BELOW average CFC access",
ins_pop <= fi_pop & cfc_per10k_fi > cfc_temp ~ "BELOW average # of food insecure people, ABOVE average CFC access",
T ~ NA),
category = factor(category, levels = c("ABOVE average # of food insecure people, BELOW average CFC access",
"ABOVE average # of food insecure people, ABOVE average CFC access",
"BELOW average # of food insecure people, BELOW average CFC access",
"BELOW average # of food insecure people, ABOVE average CFC access")))

pal2 = colorFactor(
palette = c("#EB9E87", "#D93403", "#58A8F0", "#A1CBF1"),
domain = levels(ntas$category),
na.color = "grey"
)

# plot
map = leaflet() %>%
addPolygons(data = ntas, weight = 0, color = ~pal(category),
fillOpacity = 1, smoothFactor = 0) %>%
addPolygons(data = ntas, weight = 0, color = ~pal2(category),
fillOpacity = 1, smoothFactor = 0,
popup = ~paste0("<strong>", round(cfc_per10k_fi, 1),
"</strong> CFC locations per 10k food insecure residents<br>",
"<strong>CFC locations:</strong> ", cfc_count, "<br>",
"<strong>Total population:</strong> ", round(population, 0), "<br>",
"<strong>Food insecure population:</strong> ",
round(population*food_insecurity_2023, 0))) %>%
addPolygons(data = parks, color = "grey", fillColor = "grey", weight = 0,
fillOpacity = 1, smoothFactor = 0) %>%
addCouncilStyle(add_dists = T,
highlight_dists = c(43, 15, 18, 8, 10, 14, 25, 34, 48, 38, 40, 20)) %>%
addCouncilStyle(add_dists = F) %>%
addSourceText("Source: NYC Open Data") %>%
addLegend_decreasing(position = "topleft", pal = pal,
addLegend_decreasing(position = "topleft", pal = pal2,
values = unique(ntas$category),
title = paste0("Areas with high food insecurity in need of additional support"),
opacity = 1, decreasing = T)

saveWidget(map, file=file.path('visuals', "CFC_locations_support.html"))
mapview::mapshot(map,
file = file.path("visuals", "CFC_locations_support.pdf"),
remove_controls = c("homeButton", "layersControl", "zoomControl"),
Expand Down
Loading

0 comments on commit 315eef8

Please sign in to comment.