Draft 4/17/2019

CDE Community Asset Mapping

This is a document created for the Colorado Department of Education School Nutrition unit in association with the Colorado Health Foundation “Blueprint to End Hunger”

The purpose of this is to quickly and easily combine and utilize existing public data regarding child nutrition programs in Colorado and present that data in a form that can help to inform the decisions at the state level to provide assistance, resources, and technical support to districts identified as priority areas.

This project is currently in progress and therefore errors may be present.

Gathering the shape geometry

The a general variable is first gathered from the American Community Survey, this is matched with similar information from the US Census and Tigris package to determine the shape and location of each school district.

School District Profiles

Next school district profiles, a file provided by the CDE Nutrition Unit is imported to be used to support information regarding 4 day school weeks, program participation and Sponsor or agreement number for each district, this number is standardized accross datasources and will be the matching element for each subsequent data injection.

Match SFA Agreement number to GEOID

The census and CDE have different numbering protocols therefore a library was build to match each SFA GEOID to the cooresponding CDE Agreement/Sponsor number. This next step brings that data into the environment and combines it with the previous profiles. Finally it connects both the profiles and GEOID data and shape files into a shape frame data frame called combined_geo_dist

Meal Count over time

Three different representations of the way meal counts have changed over time since 2010-2018

Four Day School Weeks

The proliferation of 4 day schools weeks is seen as a threat to food security for students who depend on child nutrition programs for daily meals. The proportion of school districts utilizing 4 days school weeks is significant.

Refining Meal Counts

Condensing monthly meal counts which can be instructive on the large scale to condensed yearly counts by SFA, Year, and Meal program

Also begins work determining ADP of programs.

Monthly ADP over time

This Graph shows the ADP of all districts by month between 2010-2018

Calculating SFSP Variables

Uses 2017-2018 SFSP data to determine the number of sites and meals served per district for each year

Create the final dataframe with all the required components

Calculate the risk scores for all districts overtime

final_district_dataframe_popups <- paste0("District Name: ", final_district_dataframe$sfa_name, "<br>",
                                          "Free and Reduced Percent: ", round(final_district_dataframe$free_and_red_perc, digits = 3), "<br>",
                                          "Score: ", final_district_dataframe$score, "<br>", 
                                          #"ADP Average: ", round(final_district_dataframe$adp_average, digits = 3), "<br>",
                                          "School Breakfast Program: ", final_district_dataframe$sbp, "<br>",
                                          "National School Lunch Program: ", final_district_dataframe$nslp, "<br>",
                                          "Afterschool Snack Program: ", final_district_dataframe$snack, "<br>",
                                          "Special Milk Program", final_district_dataframe$smp, "<br>"
)

score_pal <- colorNumeric(palette = "plasma", 
                                domain = final_district_dataframe$score)

#score_map <- 
  
final_district_dataframe %>% 
  st_transform(crs = "+init=epsg:4326") %>% 
  leaflet(options = leafletOptions(MaxZoom = 5)) %>% 
  #setView(lng = -106, lat = 39.6, zoom = 6.5, 
          #setMaxBounds(lng1 = 41,lat1 =  -110,lng2 = 40.979898,lat2 = -109)) %>% 
  setView(lng = -106, lat = 39.6, zoom = 6.5) %>% 
  addProviderTiles("Esri.WorldGrayCanvas") %>% 
  addPolygons(popup = final_district_dataframe_popups,
              stroke = FALSE,
              smoothFactor = 0,
              fillOpacity = 0.6,
              color = ~ score_pal(score),
              highlightOptions = highlightOptions(color = "white", weight = 2,
                                                  bringToFront = TRUE)) %>%
  addLegend("bottomright", 
            pal = score_pal, 
            values = ~ score,
            title = "Evaluated Risk Score",
            opacity = 1)
#htmlwidgets::saveWidget(score_map, file="scoremap.html", selfcontained= TRUE)

#score_map
# Couple things want multiple layers, SFSP, NSLP, Scores, etc. 

# Need to restrict sizes and movement

# 

final_district_dataframe_popups_sfsp <- paste0(
  "District Name: ", final_district_dataframe$sfa_name, "<br>",
  "Free and Reduced Percent: ", round(final_district_dataframe$free_and_red_perc, digits = 3), "<br>",
  "SFSP Site Count: ", final_district_dataframe$site_count_sfsp, "<br>",
  "SFSP Average ADP: ", final_district_dataframe$adp_sfsp_2018)

sfsp_pal <- colorNumeric(palette = "plasma", 
                                domain = final_district_dataframe[["adp_sfsp_2017"]])
# final_district_dataframe %>% 
#   st_transform(crs = "+init=epsg:4326") %>% 
#   leaflet() %>% 
#   addProviderTiles("Esri.WorldGrayCanvas") %>% 
 


final_district_dataframe_popups_score <- paste0(
  "District Name: ", final_district_dataframe$sfa_name, "<br>",
  "Free and Reduced Percent: ", round(final_district_dataframe$free_and_red_perc, digits = 3), "<br>",
  "Score: ", round(final_district_dataframe$score, digits = 3), "<br>", 
  "School Breakfast Program: ", final_district_dataframe$sbp, "<br>",
  "National School Lunch Program: ", final_district_dataframe$nslp, "<br>",
  "Afterschool Snack Program: ", final_district_dataframe$snack, "<br>",
  "Special Milk Program: ", final_district_dataframe$smp)

score_pal <- colorNumeric(palette = "plasma", 
                                domain = final_district_dataframe[["score"]])
#map <- 

final_district_dataframe %>% 
  st_transform(crs = "+proj=longlat +datum=WGS84")%>% 
  filter(meal_type == "NSLP") %>% 
  leaflet() %>% 
  addPolygons() %>% 
  # st_transform(crs = "+init=epsg:4326") %>% 
  # leaflet(width = "25%" ,height = "25%" ,options = leafletOptions(minZoom = 6)) %>% 
  addProviderTiles("Esri.WorldGrayCanvas") %>% 
  addPolygons(popup = final_district_dataframe_popups_score,
              group = "Score",
              stroke = FALSE,
              smoothFactor = 0,
              fillOpacity = 0.6,
              color = ~ score_pal(score),
              highlightOptions = highlightOptions(color = "white", weight = 2,
                                                  bringToFront = TRUE)) %>%
  addLegend("bottomright",
            group = "Score",
            pal = score_pal,
            values = ~ score,
            title = "Evaluated Risk Score",
            opacity = 1) %>%
  addPolygons(popup = final_district_dataframe_popups_sfsp,
              group = "SFSP",
              stroke = FALSE,
              smoothFactor = 0,
              fillOpacity = 0.6,
              color = ~ sfsp_pal(adp_sfsp_2017),
              highlightOptions = highlightOptions(color = "white", weight = 2,
                                                  bringToFront = TRUE)) %>%
  addLegend("bottomright",
            group = "SFSP",
            pal = sfsp_pal,
            values = ~ adp_sfsp_2017,
            title = "adp_sfsp_2017",
            opacity = 1) %>%
  addLayersControl(
    baseGroups = c("Score", "SFSP"),
    options = layersControlOptions(collapsed = FALSE, position = "topleft")) %>%
  hideGroup("SFSP")
#htmlwidgets::saveWidget(map, file="map1.html", selfcontained= TRUE)

#map

End of Document