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 - R Tutorial
From the course: R: Interactive Visualizations with htmlwidgets
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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
What is the Leaflet library?6m 10s
-
(Locked)
Create interactive scattergeo maps9m 56s
-
(Locked)
Change map styles in Leaflet4m 36s
-
(Locked)
Prepare data for a choropleth plot9m 48s
-
(Locked)
Create interactive choropleth maps10m 7s
-
(Locked)
Create interactive geolines maps13m 50s
-
(Locked)
Add legends to Leaflet maps7m 52s
-
(Locked)
Extract click information from Leaflet6m 35s
-
-
-
-
-
-