From the course: R: Interactive Visualizations with htmlwidgets

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Add legends to Leaflet maps

Add legends to Leaflet maps - R Tutorial

From the course: R: Interactive Visualizations with htmlwidgets

Start my 1-month free trial

Add legends to Leaflet maps

- [Instructor] Let's look how to add legends to Leaflet maps. We're going to work with three different types of map. First, a scatter geomap, second a Choropleth with a continuous color scale, and thirdly a Choropleth with a categorical scale. Let's start with a scatter geo first. So let's load up scattergeo_legend.R. Let's minimize the environment, because I don't care to see it for this exercise. At the top of our script file, we load the tidyverse library. We'll run that with Command-Enter. This loads the standard libraries from tidyverse. Then we'll load leaflet, which is the actual HTML widget we're using to create our interactive maps. And we'll hit Command-Enter. Then on line four we're using read_csv, from the readr library to import our data from a CSV file and store it against the variable capital_cities. Then, line six through 10 generate me a scatter geo plot. Let's run that code with Command-Enter, and we can see I have a world map with circles where there are capital…

Contents