Get access to all lessons in this course.
Mapping with R
- Welcome to Mapping with R (01_01)
- 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)
- 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)
- 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)
- You Did It!
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.
Click on the transcript to go to that point in the video. Please note that transcripts are auto generated and may contain minor inaccuracies.
library(sf) library(tidyverse) library(mapview) england_sf <- read_sf("data/uk-local-authorities/england.shp") scotland_sf <- read_sf("data/uk-local-authorities/scotland.shp") wales_sf <- read_sf("data/uk-local-authorities/wales.shp") uk_sf <- scotland_sf %>% bind_rows(wales_sf) %>% bind_rows(england_sf) referendum_results <- read_csv("data/esw_referendum_results.csv") uk_sf %>% left_join(referendum_results, by = c("geo_code" = "area_code")) %>% mapview(zcol = "result")
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
Import the referendum results .csv file
left_join()to join the UK shapefiles with the referendum results
mapview(zcol = "results")to visualise the shapefiles after joining
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.