filmov
tv
R Tutorial: Introduction to leaflet
Показать описание
---
Welcome to this course on creating interactive maps using the leaflet package. I'm Rich Majerus, 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 are used by leading technology companies, nonprofits, and government organizations to create informative and interactive maps.
For example, the National Parks 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 will work towards building an interactive map like the one shown on this slide. This leaflet map plots all four-year colleges in America and color codes these institutions by sector to indicate if they are 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 will 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 will 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 and 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 is 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 into the addTiles() function to create an interactive map with just two-lines of R code!
In Chapter 1, you will 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.
#R #RTutorial #DataCamp #Interactive #Maps #leaflet