Objective: To create an interactive map using leaflet. 1. Import Libraries
library(leaflet)
I will create an interactive map using leaflet to show Bangalore,Karnataka in India.
Determine the Location data I am going to pinpoint the tourist attractions in Bangalore. Given below are the coordinates of five well-known tourist attractions of Bangalore.
ban_landmarks <- data.frame(
Landmark = c("Cubbon Park",
"Nandi Hills",
"Tip Sultan's Palace",
"Lal Bagh Botanical Garden",
"Bangalore Palace"),
Latitude= c(12.973826,12.9716,12.9594, 12.9494, 13.0035),
Longitude= c(77.590591,77.5946,77.5736,77.5847,77.5891 ))
ban_landmarks
## Landmark Latitude Longitude
## 1 Cubbon Park 12.97383 77.59059
## 2 Nandi Hills 12.97160 77.59460
## 3 Tip Sultan's Palace 12.95940 77.57360
## 4 Lal Bagh Botanical Garden 12.94940 77.58470
## 5 Bangalore Palace 13.00350 77.58910
Additionally, the five places are enclosed within the boundaries of bangalore, the coordinates that covers bangalore is provided below:
ban_area <- data.frame(
lng = c(77.5946),
lat = c(12.9716))
Create the interactive Map Now, I have compiled all the data available to create an interactive map for the tourist attractions in Bangalore.
ban_landmarks %>%
leaflet() %>%
addTiles() %>%
addMarkers(lng = ban_landmarks$Longitude, lat = ban_landmarks$Latitude,
popup = ban_landmarks$Landmark, clusterOptions = markerClusterOptions()) %>%
addPolygons(lng = ban_area$lng, lat = ban_area$lat, fillColor = 'yellow', color = 'black', weight = 10) %>%
addLegend(labels = 'Bangalore', colors = 'yellow')