In this week assignment, we will build an interactive map in R using
the leaflet package.
Load the package:
library(leaflet)
Feature the current date:
today <- Sys.Date()
format(today, format="%B %d, %Y")
[1] "August 04, 2022"
Create a data frame which contains the latitudes, longitudes and name some of the most popular cities in my country, Viet Nam.
df <- data.frame(
name = c("Ho Chi Minh city", "Can Tho city", "Da Nang city", "Ha Noi city"),
lat = c(10.777707638668417, 10.032482788518974, 16.061231818072404, 21.03918760364837),
lng = c(106.6955783317747, 105.78815569559849, 108.2273211603241, 105.83476591596742)
)
Draw the map:
df %>% leaflet() %>%
addTiles() %>%
addMarkers(popup = df$name)