This is the first project assignment for the Developping Data Products course in Coursera’s Data Science specialization track. The purpose of this project is to create an interactive map with leaflet R package. I will create an interactive map with the location of the public transport stations in Paris. Data is downloaded from RATP’s open data website.
if (!require("leaflet")) {
install.packages("leaflet")}
## Loading required package: leaflet
library(leaflet)
if(!file.exists("./DataProduct")) {
dir.create("./DataProduct")}
if(!file.exists("./DataProduct/positions-geographiques-des-stations-du-reseau-ratp.csv")) {
fileUrl1 <- "https://dataratp2.opendatasoft.com/explore/dataset/positions-geographiques-des-stations-du-reseau-ratp/download/?format=csv&timezone=Europe/Berlin&use_labels_for_header=true"
download.file(fileUrl1, destfile="./DataProduct/positions-geographiques-des-stations-du-reseau-ratp.csv")}
RATP <- read.csv("./DataProduct/positions-geographiques-des-stations-du-reseau-ratp.csv", header=TRUE, sep=";")
dim(RATP)
## [1] 26560 8
head(RATP)
## stop_id stop_name
## 1 2158 Achères-Ville
## 2 2159 Alésia
## 3 2172 Concorde
## 4 2174 Convention
## 5 2178 Courcelle-sur-Yvette
## 6 2187 Denfert-Rochereau
## stop_desc
## 1 Avenue de Conflans - 78005
## 2 Place Victor et Hélène Basch - 75114
## 3 Tuileries (jardin des, face au 246 rue de Rivoli et Ã<U+0088> la rue Cambon) PARIS-08 - 75108
## 4 Vaugirard (337 rue de) - 75115
## 5 Rue Fernand Leger - 91272
## 6 Général Leclerc (4 avenue du, 2 rue Daguerre) - 75114
## coord stop_lat stop_lon code_INSEE departement
## 1 48.9700771763, 2.07761818201 48.97008 2.077618 78005 78
## 2 48.8280660197, 2.32682742005 48.82807 2.326827 75114 75
## 3 48.8654893909, 2.32141178921 48.86549 2.321412 75108 75
## 4 48.8371369496, 2.29639609016 48.83714 2.296396 75115 75
## 5 48.7007630181, 2.09910052706 48.70076 2.099101 91272 91
## 6 48.8333151859, 2.33344276383 48.83332 2.333443 75114 75
str(RATP)
## 'data.frame': 26560 obs. of 8 variables:
## $ stop_id : int 2158 2159 2172 2174 2178 2187 2188 2198 2210 2212 ...
## $ stop_name : Factor w/ 5279 levels "11 NOVEMBRE",..: 42 57 1081 1094 1125 1257 1331 1606 1747 1774 ...
## $ stop_desc : Factor w/ 10645 levels "0 ALL SANTO TIRSO - 92024",..: 6663 9749 10583 10589 10340 9406 6523 9526 10098 10285 ...
## $ coord : Factor w/ 12140 levels "48.669856075, 2.3317854623",..: 11735 3940 6739 4466 189 4212 10872 4952 5134 7825 ...
## $ stop_lat : num 49 48.8 48.9 48.8 48.7 ...
## $ stop_lon : num 2.08 2.33 2.32 2.3 2.1 ...
## $ code_INSEE : int 78005 75114 75108 75115 91272 75114 93029 94033 75112 75110 ...
## $ departement: int 78 75 75 75 91 75 93 94 75 75 ...
Icon <- makeIcon(
iconUrl = "http://www.pngfactory.net/png/18585/Ratp/download-png",
iconWidth = 35*215/230, iconHeight = 35,
iconAnchorX = 35*215/230/2, iconAnchorY = 35) # retrieve RATP logo to add on the map at each station location
MetroCoords <- data.frame(
lat = RATP$stop_lat,
lng = RATP$stop_lon) # prepare a dataframe with GPS coordinates
StationName <- paste("<a href='", "'>", RATP$stop_name,"</a>" ,sep = "")
InteractiveMap <- MetroCoords %>% leaflet() %>% addTiles() %>% addMarkers(clusterOptions = markerClusterOptions, icon=Icon, popup = StationName)
InteractiveMap