Leaflet is an JavaScript library for building interactive maps. RStudio released a package that allows us to build these maps in R!
You can do some really cool things in Leaflet, and I will demonstrate a few of those below. Leaflet is compatible with Shiny apps and R Markdown documents.
As mentioned on the RStudio page, the basic steps to create a Leaflet map are:
1. Create a map widget using leaflet()
2. Add layers to the map using addTiles(), addMarkers(), etc.
3. Print the map.
Okay, let’s get started. We will need the leaflet and magrittr packages for this.
Let’s create a basic map centered at San Francisco. First, we create a widget by calling leaflet(). Then, we add tiles to the map using addTiles(). By default, it uses Open Street Map tiles. If you would like to use other tiles, please refer here. We can set the desired longitude and latitude that we want the map to be centered at, and also set the zoom level using the setView() function. The addMarker() function allows us to add a marker at our desired location, with it’s own popup message!
Visit this web page to read the complete article.