The R leaflet package is an interface to the JavaScript library Leaflet to create interactive web maps IN R. It was developed by RStudio team on top of the htmlwidgets framework, which means the maps can be rendered in R console, Rstudio IDE, R Markdown, R Shiny apps.

Install the R Leaflet package if not already from the CRAN mirror near you using the install.packages() function and load it.

install.packages("leaflet")
library(leaflet)

We start with creating a map widget using the leaflet() function, supply the data of interest, add methods or layers on map widget and done!!!

Adding layers to leaflet map widget can be done through the pipe operator %>% from magrittr package. Pipe operator is not mandatory to use, however makes life easier by avoiding nested commands.

Let’s look at an example next