Objective
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.
Review Criteria
The rubric contains the following two questions:
Does the web page feature a date and is this date less than two months before the date that youโre grading this assignment?
Does the web page feature an interactive map that appears to have been created with Leaflet?
Assignment
if (!require(leaflet)){
install.packages("leaflet")
library(leaflet)
}
## Loading required package: leaflet
Here, I want a map of bangalore with some famous eateries. For that I need a data frame having the coordinates of these places and the name of the eateries.
lat <- c(12.94731, 12.94861, 12.93770, 12.95536, 12.94486)
long <- c(77.57148,77.59892, 77.57995, 77.58554, 77.56046)
eat_name <- c("MLTR","Janatha Hotel", "Hotel Sanman", "MTR", "Hotel Mangala")
df <- data.frame(eat_name,lat,long)
head(df)
eat_name lat long
1 MLTR 12.94731 77.57148
2 Janatha Hotel 12.94861 77.59892
3 Hotel Sanman 12.93770 77.57995
4 MTR 12.95536 77.58554
5 Hotel Mangala 12.94486 77.56046
Using leaflet and mapping the coordinates.
m <- leaflet() %>%
addTiles() %>%
addMarkers(lat = df$lat,
lng = df$long,
label = df$eat_name,
labelOptions = labelOptions(noHide = T, textsize = "15px"))
m
Mapping Clusters
When you zoom in to each cluster, the cluster will separate until individual markers are visible.
cluster_points <- data.frame(
lat = runif(500, min = 12.92, max = 12.96),
lng = runif(500, min = 77.5, max = 77.6)
)
cluster_points %>%
leaflet() %>%
addTiles() %>%
addMarkers(clusterOptions = markerClusterOptions())