Get access to all lessons in this course.
- Welcome to Mapping with R (01_01)
-
Geospatial Data
- Making Maps is Complex (01_02)
- mapview for Quick Maps (01_03)
- sf for Simple Features (01_04)
- Turning Data Frames into sf Objects (01_05)
- Importing Shapefiles (01_06)
- Joining Geospatial Datasets (01_07)
- Disambiguating Country Names (01_08)
- Converting Addresses to Coordinates (01_09)
- U.S.-Specific Datasets (01_10)
- Advice on Finding International Datasets (01_11)
- CRS and Projections: Geographic and Projected CRS (01_12)
- CRS and Projections: How to Choose a CRS (01_13)
- Introducing Raster GIS with raster and stars (01_14)
- Basics of Using the raster Package (01_15)
-
Static Maps
- ggplot2 Essentials (02_01)
- Starting a Map in ggplot2 (02_02)
- Labelling ggplot2 Maps (02_03)
- Compare Locations/Events with Geobubble Charts (02_04)
- Highlight a Region in a Country with ggplot2 (02_05)
- Make a Choropleth Map of Discrete Variables with ggplot2 (02_06)
- Make a Choropleth Map of Continuous Variables with ggplot2 (02_07)
- Faceting Choropleth Maps with ggplot2 (02_08)
- Visualize Raster Data with ggplot2 (02_09)
- Adding Scale Bars and North Arrows with ggplot2 (02_10)
-
Interactive Maps
- What is leaflet? (03_01)
- Starting a Map in leaflet (03_02)
- Necessary HTML for Labelling leaflet Maps (03_03)
- Highlight a Region in a Country with leaflet (03_04)
- Compare Locations/Events with Geobubble Charts in leaflet (03_05)
- Make a Choropleth Map of Discrete Variables with leaflet (03_06)
- Make a Choropleth Map of Continuous Variables with leaflet (03_07)
- Visualize Raster Data with leaflet (03_08)
-
Wrapping Up
- You Did It!
Mapping with R
Make a Choropleth Map of Discrete Variables with ggplot2 (02_06)
This lesson is locked
This lesson is called Make a Choropleth Map of Discrete Variables with ggplot2 (02_06), part of the Mapping with R course. This lesson is called Make a Choropleth Map of Discrete Variables with ggplot2 (02_06), part of the Mapping with R course.
Transcript
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 up the 02_06
project.
Use the your-turn.R
script in 02_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
In this video there was quite a lot of information about how to work with factors using the {forcats} package.
While factors are part of base R it’s fairly painful to manipulate the levels of factors without the {forcats} package. The factors chapter of R for Data Science gives a great overview of both factors and {forcats}.
The paletteer package is an excellent resource for discovering useful color palettes. However, it’s very important to consider if your maps will make sense to readers with color blindness. Thankfully, the {colorblindr} package simplifies this with the following code:
remotes::install_github("wilkelab/cowplot")
colorblindr::cvd_grid(your_gg_map)
You need to be signed-in to comment on this post. Login.
Kristina Bratkova
March 5, 2022
Hello,
thanks for this clear video. I was wondering if lines 37-38 are redundant if scale_fill_manual is used? (scale_fill_manual is set by the ordered factor given in the list of colours (which was set by base R syntax to be in order of descending area of the region))
Charlie Hadley
March 7, 2022
Hi Kristina! This is a great question, and an absolutely correct observation. I made a quick gist to show that you're right, commenting out the fct_relevel() line isn't necessary to fix legend orders when using scale_fill_manual().
It's still a good idea to set the levels of your factors as they might have consequences in other aesthetics of your chart. Here's a slightly tautological example to demonstrate this. Let me know if you have any follow up questions. Cheers, Charlotte
Kristina Bratkova
March 10, 2022
Hello Charlotte,
many thanks for your answer, very interesting example!
Oscar Tetteh
April 7, 2023
Hello Charlotte,
I am trying to relate this to my current research. I have a shapefile and data sets. The aim is to map the data set to the shapefile. could you please help me with the codes or a recommendation?
Thank you
David Keyes
April 9, 2023
Hi Oscar, we unfortunately can't provide this type of personal support. If you have any questions about running code in the lessons, please let us know!