Chapter 69 Maps of Food Places

69.1 Pass or Fail Spots

ResultsPassORFail = c("Pass","Fail")

factpal <- colorFactor(c("gray","red","purple","yellow","orange","green","blue"), 
                       FoodInspections$Results)

FoodInspectionsSubSet = FoodInspections %>%
  sample_n(8e3) %>%
  filter(Results %in%  ResultsPassORFail) 

leaflet(FoodInspectionsSubSet) %>% addProviderTiles("Esri.NatGeoWorldMap") %>%
  addCircles(lng = ~Longitude, lat = ~Latitude,radius = 1, 
             color = ~factpal(Results))  %>%

  addLegend("bottomright", pal = factpal, values = ~Results,
            title = "Locations of Food Places in Chicago",
            opacity = 1)

The plot shows more Greens i.e. Pass across the shoreline than the Reds i.e. Fail. You may want to zoom in and zoom out and play with the map to find out more.

69.2 Out of Business Spots

ResultsOOB = c("Out of Business")

factpal <- colorFactor(c("gray","red","purple","yellow","orange","green","blue"), 
                       FoodInspections$Results)

FoodInspectionsSubSet = FoodInspections %>%
  sample_n(8e3) %>%
  filter(Results %in%  ResultsOOB) 

leaflet(FoodInspectionsSubSet) %>% addProviderTiles("Esri.NatGeoWorldMap") %>%
  addCircles(lng = ~Longitude, lat = ~Latitude,radius = 1, 
             color = ~factpal(Results))  %>%

  addLegend("bottomright", pal = factpal, values = ~Results,
            title = "Locations of Food Places in Chicago",
            opacity = 1)
FoodInspectionsReduced = FoodInspections %>%
  mutate(InspectionID = `Inspection ID`) %>%
  select(InspectionID,Violations,Results)

FoodInspectionWords <- FoodInspectionsReduced %>%
  unnest_tokens(word, Violations) %>%
  filter(!word %in% stop_words$word) %>%
  dplyr::count(Results, word, sort = TRUE) %>%
  ungroup()