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
Joining Geospatial Datasets (01_07)
This lesson is locked
This lesson is called Joining Geospatial Datasets (01_07), part of the Mapping with R course. This lesson is called Joining Geospatial Datasets (01_07), 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 project 01_07
.
Use mapview()
to visualise the results of the Brexit Referendum by combining shapefiles with the a .csv file containing the results.
Combine together the shapefiles for England, Scotland and Wales with
bind_rows()
Import the referendum results .csv file
Use
left_join()
to join the UK shapefiles with the referendum resultsUse
mapview(zcol = "results")
to visualise the shapefiles after joining
Learn More
As mentioned in the video, there are animated GIFs explaining how each of the mutating join functions work on the tidyexplain
website. The Going Deeper with R course also covers the mechanics of joins in more detail.
It’s important to remember that the sf
object must always go in the first argument of your joins, otherwise the geometry information will be lost.
It’s often necessary to disambiguate country names using a join and the countrycode
package, which is covered in the next lessons.
You need to be signed-in to comment on this post. Login.
J. Jesús Bautista-Romero
February 23, 2022
Charlotte: A comment: I first used "by = c("name" = "area_name"))" to join the objects in the left_join(), then I saw your video and you used the code columns to join them and the maps were a little different. I understand that some names are dissimilar between shape and csv objects and this result in NAs cells of the right side columns. by the way, amazing lessons, you teach very well
Regards.
Jesús
David Keyes
February 25, 2022
Hi Jesús, just a quick note to say that Charlie is sick this week, but will get back to you soon!
J. Jesús Bautista-Romero
February 25, 2022
Hi David. So sorry about that news. I wish Charlie a quick recovery, a lot of good vibes.
Charlie Hadley
March 3, 2022
Thanks for the well wishes, Jesús! This is a good example of how GIS datasets can be unexpectedly annoying. When you join using
by = c(“name” = “area_name”))”
there are 7 areas with NA values, you can see several of these areas as grey in the map. I'll concentrate on the south most, which hasname = Cornwall,Isles of Scilly
butarea_name = Cornwall
. Which means in the uk_sf object both the area of Cornwall and the Isles of Scilly are combined into one. That's very unexpected. I'd recommend if you have geographic codes to always use them if possible as these are much more likely to give you useful values. I'm really glad you're enjoying the course! Cheers, CharlieJay Cutler
March 14, 2022
Hi Charlie, I noticed that in your example, countries like the Republic of Congo were omitted from the final map because the text under 'name' (world_sf) and 'country' (gapminder_2007) were not the same. Do you have a process to match up the names of geographic units besides carefully reviewing datasets before joining and using mutate(case_when()) to fix inconsistencies? Thanks!
Jay Cutler
March 14, 2022
Well, looks like I just needed to watch the next class before sending this!
Charlie Hadley
March 15, 2022
Ha! There's an argument for the "disambiguating country names" video to come first but to do it properly you need to know how to join first 😀
David Solet
March 28, 2022
Hello Charlie, In the solution, I'm not sure where "brexit_votes" came from. To check, I ran the code and it resulted in an error, not found. Sorry if I missed something! (My result seemed to be fine.)
Charlie Hadley
March 29, 2022
Hi David! Thanks for commenting, you caught a mistake! In the Gist solution it did erroneously use
brexit_votes
from an earlier draft but I changed my mind and usedreferendum_results
later on.I've updated the solution now so hopefully it won't cause any confusion for anyone else.
Thanks, Charlie
David Solet
March 30, 2022
Hello Charlie, Thanks for the correction. Overall, I'm really enjoying the course! David