Goal of the excercise is to generate a map using leaflet, using R markdown. In this excercise we downloaded the set from the open data site: http://data.groningen.nl/afvalcontainers-gemeente-groningen/. The used csv file is: http://data.groningen.nl/wp-content/uploads/2013/11/Afvalcontainers-gemeente-Groningen_GPS_open_data.csv
For this exercise i’ve downloaded the set to prevent traffic to the original site. First a quick peek at the data structure…
gcl <- read.csv2("Afvalcontainers-gemeente-Groningen_GPS_open_data.csv", header = TRUE)
gcl <- na.omit(gcl) # lets drop any row with NA's in it.
head(gcl)
## locatie typering omschrijving x y
## 1 Rabenhauptstraat OND Rabenhauptstraat 53.20972 6.571528
## 2 Groen van Prinstererlaan OND Groen van Prinstererlaan 53.19340 6.593434
## 3 Oosterhamrikkade NZ Oost OND Oosterhamrikkade NZ Oost 53.23094 6.578489
## 4 Hamburgerstraat Zuid OND Hamburgerstraat Zuid 53.23173 6.577699
## 5 Melkweg Midden OND Melkweg Midden 53.21728 6.554670
## 6 Rembrandt van Rijnstraat Zuid OND Rembrandt van Rijnstraat Zuid 53.21592 6.545149
Since the map is pretty much a local map, i zoomed in; furthermore, i used the clusetrmarker since we have a lot of containers in a small area… To be able to used the data we have to convert the columns x and y to latitude and longitude.
You may click on a marker to see some detail about the container, i.e street and type
# rename columns
names(gcl)[names(gcl)=='x']<-"latitude"
names(gcl)[names(gcl)=='y']<-"longitude"
library(leaflet)
## Warning: package 'leaflet' was built under R version 3.3.2
gcl %>% leaflet() %>% addTiles() %>% addMarkers(clusterOptions = markerClusterOptions(),
lat=gcl$latitude, lng=gcl$longitude,
popup=paste(gcl$omschrijving,", type:", gcl$typering))
Note that one containers seems to be ‘lost’ at sea…