Loading Library

library(leaflet)
library(tidyverse)

Initializing map object

Adding the longitude and latitude of Pashupatinath Temple

demoMap = setView(demoMap,lng= 85.3485809,lat = 27.71062,zoom = 15)%>% addMarkers(lng= 85.3485809,lat = 27.71062,popup = "Pashupatinath Temple, Nepal")
demoMap

Adding the quakes data and displaying the random quakes

quakesdata <- quakes[sample(nrow(quakes),20),]
leaflet(data=quakesdata)%>%addProviderTiles("Esri.WorldImagery")%>%addMarkers(lng = ~long,lat = ~lat)%>%addCircleMarkers(lng = ~long,lat = ~lat)

Adding the quakes data and displaying the random quakes with color

quakesdata <- quakes[sample(nrow(quakes),50),]
quakesdata$magRange<- cut(quakesdata$mag, breaks = c(4,5,6,7,8),right =FALSE,
                            labels = c("Light(4-5)","Moderate(5-6)","Strong(6,7)","Very Strong(7,8)"))

pal = colorFactor(palette = c("green","blue","yellow","red"),domain = quakesdata$magRange)

leaflet(data=quakesdata)%>%addProviderTiles("Esri.WorldImagery")%>%
  addCircleMarkers(lng = ~long,
             lat = ~lat, 
             color = ~ pal(magRange),
             label = paste("Magnitude=",quakesdata$mag,"Type=",quakesdata$magRange)) %>% 
  addLegend(position = "bottomright", values = ~magRange, pal = pal, title = "Magnitude Legend")