R Tutorial: Introduction to leaflet

Rich Mageris teaches Leaflet, an R package for building interactive maps. You'll learn core commands like leaflet() and addMarkers(), then map DataCamp's offices in Belgium and New York. The course project is a color-coded map of all four-year U.S. colleges with toggleable filters.
Chapters
Welcome to this course on creating interactive maps using the Leaflet package. I'm Rich Mageris, a data scientist and R instructor. Leaflet is a popular open source JavaScript library for creating mobile friendly interactive maps. Thanks to the work of many leading R developers, we can create interactive maps with just a few lines of R code. You may already be familiar with leaflet maps as they're used by leading technology companies, nonprofits and government organizations to create informative and interactive maps. For example, the National Park Service uses Leaflet to create an interactive map of America's national parks. This map enables users to explore parks and monuments by state. For example, Maine, where I live, has one national park, one international park, and one national monument. Clicking on any of these locations reveals a pop up with additional information. In this course, we'll work towards building an interactive map like the one shown on the slide. This leaflet map plots all four year colleges in America and color codes these institutions by sector to indicate if they're public, private or for profit. Using the control panel in the upper right hand corner, we can toggle the map between different base maps and we can select which sectors of colleges appear on the map. Later in the course, we'll add a few pieces of flair to this map, such as labels that appear when hovering and the ability to search for a particular college. But first, we'll learn about the core features of the leaflet library by mapping datacamp's locations in Belgium and New York. Leaflet Builds maps using tiles Tiled web maps join many map images together. When a user zooms or pans your interactive leaflet map, new tiles are fetched as needed to provide the requested view of the map. Let's take a look at how this works in R. First we load the leaflet library. Then we initialize an HTML widget with the leaflet function call. You'll notice that Leaflet leverages the pipe operator that's common in the Tidyverse. This allows us to chain a series of functions together. For example, we can pipe the result of our leaflet call and into the Add Tiles function to create an interactive map with just two lines of R code. In chapter one, you'll practice using different map tiles while working towards creating an interactive map that displays two of datacamp's locations. Similar to adding a provider tile, you can add another layer to your map using the pipe operator to include markers that identify specific locations. Now it's your turn. Let's get started by exploring the leaflet library and creating an interactive map. With the default OpenStreetMap tile.
More from Richie

#359 My Best Friend is AI with Valerie Tiberius, Professor of Philosophy at University of Minnesota

How AI Agents Will Work While You Sleep | Ruslan Salakhutdinov, Professor at Carnegie Mellon

#358 How AI Agents Will Work While You Sleep | Ruslan Salakhutdinov, Professor at Carnegie Mellon







