This document is going to be a simple document on how to create an interactive map using leaflet package.
First you’re going to need the package itself, so load it into R before we proceed. Also. I’ll load some packages that I will use for this assignment.
library(dplyr)
library(leaflet)
library(maps)
I live in Indonesia, you may know my country by one of the most popular tourism site Bali. So in this assignment, I will plot cities in Indonesia for you!
First, lets get the longitude and latitude from world.cities data in the maps package.
df <- world.cities[grep("Indonesia", world.cities$country.etc), ]
head(df)
This data contain the name of the city, population, latitude, longitude, and capital Looks good !, now lets use leaflet package to put a marker on those location!
df %>% leaflet() %>% addTiles() %>% addMarkers( popup = (as.character(df$pop)))