---
title: "Lab 14.1 - Restaurant &amp; Health Codes"
author: "Author Goes Here"
date: "Semester Goes Here"
output:
  pdf_document:
    latex_engine: xelatex
---

```{r warning=FALSE, message=FALSE}
library(tidyverse)
```

The goal of this exercise is to visualize health code violations in New York City restaurants.

🚧
Following the instructions given in Section 18.6, Problem 1.

We need to limit the number of addresses we geocode because they take around 1 second each to process.

```{r}
library(mdsr)
library(tidygeocoder)

violations_selected <- Violations %>%
  count(camis, dba, boro, building, street, zipcode) %>%
  filter(n > 92)

violations_selected
```

Here we compute the geo-coordinates, filtering out an outlier that's actually in Rochester, NY.

```{r}
library(sf)

violations_geom <- violations_selected %>%
  mutate(address = paste(building, ", ", street, ", ", boro, ", NY,", zipcode)) %>%
  tidygeocoder::geocode(address, method = "osm") %>%
  na.omit() %>%
  filter(lat < 41.0) %>%
  st_as_sf(coords = c("long", "lat")) %>%
  st_set_crs(4326)  
violations_geom
```


```{r}
library(ggspatial)

violations_geom %>%
  ggplot() +
  aes(size = n) +
  annotation_map_tile(zoomin = 0, type = "osm") +
  geom_sf()
```

See `lab141-restaurants-solution.Rmd` for the leaflet version.