head(Violations)CH 18 Problem 1 part(c) Leaflet maps
Chapter 18
Problem 1 - Part(c)
Violations$full_address <- paste(Violations$street, Violations$boro, Violations$zipcode)clean_violations <- Violations[!duplicated(Violations[5:6]),] %>%
drop_na() %>%
head(50)
head(clean_violations)# A tibble: 6 × 17
camis dba boro build…¹ street zipcode phone inspection_date action
<int> <chr> <chr> <int> <chr> <int> <dbl> <dttm> <chr>
1 30075445 MORRI… BRONX 1007 MORRI… 10462 7.19e9 2015-02-09 00:00:00 Viola…
2 30112340 WENDY… BROO… 469 FLATB… 11225 7.18e9 2015-05-07 00:00:00 Viola…
3 30191841 DJ RE… MANH… 351 WEST … 10019 2.12e9 2015-09-21 00:00:00 Viola…
4 40356018 RIVIE… BROO… 2780 STILL… 11224 7.18e9 2015-06-05 00:00:00 Viola…
5 40356151 BRUNO… QUEE… 8825 ASTOR… 11369 7.18e9 2015-05-29 00:00:00 Viola…
6 40356483 WILKE… BROO… 7114 AVENU… 11234 7.18e9 2015-05-08 00:00:00 Viola…
# … with 8 more variables: violation_code <chr>, score <int>, grade <chr>,
# grade_date <dttm>, record_date <dttm>, inspection_type <chr>,
# cuisine_code <dbl>, full_address <chr>, and abbreviated variable name
# ¹building
coords <- clean_violations %>%
tidygeocoder::geocode(full_address, method = 'osm',
lat = latitude,
long = longitude
)Passing 50 addresses to the Nominatim single address geocoder
Query completed in: 72.1 seconds
glimpse(coords)Rows: 50
Columns: 19
$ camis <int> 30075445, 30112340, 30191841, 40356018, 40356151, 4035…
$ dba <chr> "MORRIS PARK BAKE SHOP", "WENDY'S", "DJ REYNOLDS PUB A…
$ boro <chr> "BRONX", "BROOKLYN", "MANHATTAN", "BROOKLYN", "QUEENS"…
$ building <int> 1007, 469, 351, 2780, 8825, 7114, 6409, 1839, 2300, 13…
$ street <chr> "MORRIS PARK AVE", "FLATBUSH AVENUE", "WEST 57 STREE…
$ zipcode <int> 10462, 11225, 10019, 11224, 11369, 11234, 11219, 11226…
$ phone <dbl> 7188924968, 7182875005, 2122452912, 7183723031, 718335…
$ inspection_date <dttm> 2015-02-09, 2015-05-07, 2015-09-21, 2015-06-05, 2015-…
$ action <chr> "Violations were cited in the following area(s).", "Vi…
$ violation_code <chr> "06C", "04A", "06C", "08C", "04L", "06B", "04N", "10B"…
$ score <int> 6, 12, 8, 4, 12, 9, 8, 5, 9, 11, 13, 9, 7, 10, 11, 6, …
$ grade <chr> "A", "A", "A", "A", "A", "A", "A", "A", "A", "A", "A",…
$ grade_date <dttm> 2015-02-09, 2015-05-07, 2015-09-21, 2015-06-05, 2015-…
$ record_date <dttm> 2016-01-06, 2016-01-06, 2016-01-06, 2016-01-06, 2016-…
$ inspection_type <chr> "Cycle Inspection / Initial Inspection", "Cycle Inspec…
$ cuisine_code <dbl> 8, 37, 45, 3, 3, 26, 3, 41, 3, 39, 48, 41, 41, 3, 3, 2…
$ full_address <chr> "MORRIS PARK AVE BRONX 10462", "FLATBUSH AVENUE BROOKL…
$ latitude <dbl> 40.85394, 40.66055, 40.76667, 40.58490, 40.76249, 40.6…
$ longitude <dbl> -73.861145, -73.960672, -73.982757, -73.983022, -73.87…
coords %>%
filter(latitude > 40, latitude < 44) %>%
leaflet() %>%
addTiles() %>%
addMarkers(lng=~longitude, lat=~latitude,
popup = ~paste(full_address, sep = '<br/>'))