A web page that features a map using R Markdown and Leaflet is created. The map shows the locations of the electric vehicles charging stations in Barcelona’s district of Nou Barris. The locations coordinates are obtained from the Open Data BCN site.
Accessing the data source and obtaining the relevant location information.
library(downloader)
url <- "http://www.barcelona.cat/vehicle-electric/PUNTS_RECARREGA_VEHICLES_ELECTRICS_BCN_CIUTAT.csv"
filename <- "PUNTS_RECARREGA_VEHICLES_ELECTRICS_BCN_CIUTAT.csv"
download(url, destfile = filename)
library(data.table)
df <- fread(filename, drop = c(15:104))
suppressMessages(library(dplyr))
data <- unique(df %>%
select(COORDENADA_X, COORDENADA_Y, DISTRITO) %>%
filter(DISTRITO == "08 Nou Barris"))
stationsLatLong <- data.frame(
lat = as.numeric(gsub(",", ".", data$COORDENADA_X)),
lng = as.numeric(gsub(",", ".", data$COORDENADA_Y)))
Creating an icon for marking the locations.
library(leaflet)
stationsIcon <- makeIcon(
iconUrl = "https://goo.gl/0zdnO8",
iconWidth = 31*215/230, iconHeight = 31,
iconAnchorX = 31*215/230/2, iconAnchorY = 16
)
artSites <- "EV Charging Station"
Map of chargers in Barcelona’s Nou Barris district.
stationsLatLong %>% leaflet() %>%addTiles() %>%
addMarkers(icon = stationsIcon, popup = artSites)