Skip to content
R for the Rest of Us Logo

Mapping with R

34 lessons

Make a Choropleth Map of Discrete Variables with leaflet (03_06)

This lesson is locked

Get access to all lessons in this course.

If the video is not playing correctly, you can watch it in a new window


Click on the transcript to go to that point in the video. Please note that transcripts are auto generated and may contain minor inaccuracies.

Your Turn

Open project 03_06. Use the your-turn.R script in 03_06 to make this map.

  • Use the custom colors.

  • Ensure the guide is ordered by size of region.

  • Add a title to the guide.

Learn More

It is much easier to work with NA values in {leaflet} maps than with {gglot2}!

In this video I used a slightly different approach to working with factors than in the {ggplot2} video about discrete choropleth. As before, if you want to learn more about factors then I recommend the factors chapter of R for Data Science.

Have any questions? Put them below and we will help you out!

You need to be signed-in to comment on this post. Login.

Hi there Charlie; in the "my turn" example, I was expecting that Hulu would end up green, ESPN red, Netflix black ,and Amazon Prime blue. In reality, it looks like Hulu ended up black, ESPN green, Netflix red, and Amazon Prime blue (last one is in line with expectations). I think what's in your video is the same result .. . does this have to do with the arranging in the fct_rev, perhaps linked to some aspect of the unlist function? Seems like a minor point, and it took me a while to realize what I was seeing - sorry if I missed something there, thanks!

Jordan Trachtenberg

Jordan Trachtenberg

May 19, 2023

Hi Charlie, this question is beyond the scope of this video but I was hoping you could steer me in the direction of a helpful resource. Is there a way that you can create an interactive filter on your map to be able to select one or several of the categories? For instance, a button that would allow me to select only the Netflix datapoints? I'm guessing this requires Shiny and more extensive programming but I thought I would ask. The reason I'm asking is because I'm trying to make a map dashboard with various filter variables like company, date, and cost that I would like the user to be able to filter.