This represents an assignment submission for the Coursera Developing Data Products class. This course if offered by the John Hopkins University as part of the Data Science Specialization.
Create a web page using R Markdown that features a map created with Leaflet.
Host your webpage on either GitHub Pages, RPubs, or NeoCities.
Your webpage must contain the date that you created the document, and it must contain a map created with Leaflet. We would love to see you show off your creativity!
Data representing the locations of docking stations for the Santander Cycles hire scheme was obtained from the London Datastore. Location information and the number of docking stations was then extracted and displayed using the Leaflef for R package.
The display provides a static view of the total number of docking points available at each location and does not reflect active hires or bicycles not in service.
library(leaflet)
library(xml2)
cycleData.url <- "https://tfl.gov.uk/tfl/syndication/feeds/cycle-hire/livecyclehireupdates.xml"
cycleData.xml <- read_xml(cycleData.url)
stations <- xml_find_all(cycleData.xml, "//station")
station.data <- data.frame(id=xml_integer(xml_find_all(stations, "//id")),
name=xml_text(xml_find_all(stations, "//name")),
lat=xml_double(xml_find_all(stations, "//lat")),
lng=xml_double(xml_find_all(stations, "//long")),
installed=xml_text(xml_find_all(stations, "//installed")),
numberDocks=xml_integer(xml_find_all(stations, "//nbDocks")))
bicycleIcon <- makeIcon(
iconUrl = "./images/bicycle.svg",
iconWidth = 20*215/230, iconHeight = 20,
iconAnchorX = 20*215/230/2, iconAnchorY = 20
)
station.data %>%
leaflet() %>%
addTiles() %>%
setView(lng = -0.12755, lat = 51.5073, zoom = 12) %>%
addMarkers(~lng, ~lat,
popup = paste("<table><tr><td><b>Name:</b></td><td>",
as.character(station.data$name),
"</td></tr></table>",
"<table><tr><td><b>Location:</b></td><td>",
as.character(station.data$lat),
"N, ",
as.character(station.data$lng),
"E</td></tr></table>",
"<table><tr><td><b>Docks:</b></td><td>",
as.character(station.data$numberDocks),
"</td></tr></table>"),
clusterOptions = markerClusterOptions(),
icon=bicycleIcon)
Powered by TfL Open Data Contains OS data © Crown copyright and database rights 2016