Skip to content
R for the Rest of Us Logo

Mapping with R

34 lessons

sf for Simple Features (01_04)

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 the 01_04.Rproj file in order to open the appropriate project. From there:

Use mapview() to visualise only the regions in tiny_countries110 where the UN region is either “Seven Seas (open ocean)” or “Oceania”.

  • Load the {tidyverse}, {mapview}, {rnaturalearthdata} and {sf} packages

  • Convert tiny_countries110 into an sf object

  • Filter only those countries in “Seven Seas (open ocean)” or “Oceania”

  • Visualise this object with {mapview}

Learn More

If you want to learn more about how the sf package handles simple features data visit its website. Please note that it can do a lot of complex geospatial analysis, most of which is not covered in this course. If you want to learn about doing this type of work, check out Geocomputation with R.

The video demonstrates how to work with objects that have the class “sf” “data.frame” because they work just like normal data.frames. Sometimes you’ll need to work with the lower-level geometry objects but this is rare.

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

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

Latif Apaassongo Ibrahim

Latif Apaassongo Ibrahim

February 20, 2022

Similar to my previous concern, I think I can only visualize the basemaps but not any map features. When I use codes in the example files, I can see country but not county boundaries. I can neither see the blue colored polygons in the videos nor interact with the output. I am using R version 4.1.2 (2021-11-01) -- "Bird Hippie". Could that be the problem?

Oscar Tetteh

Oscar Tetteh

March 29, 2023


Please, my data is now showing in the global environment.

It says: Error in counties_sf("laea") : could not find function "counties_sf"

Hannah Ridenour LaFrance

Hannah Ridenour LaFrance

July 18, 2023

Hi, I've been unsuccessful at installing the albersusa package, being told that "there is no package called "albersusa"" - I'm running on R 4.3.1 and RStudio 2023.06.1+524 "Mountain Hydrangea" Release (547dcf861cac0253a8abb52c135e44e02ba407a1, 2023-07-07) for windows Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) RStudio/2023.06.1+524 Chrome/110.0.5481.208 Electron/23.3.0 Safari/537.36

Kendall Beals

Kendall Beals

January 23, 2024

Hi, thank you for creating this course! I've run into a similar issue with the previous mapview module (1_03). I've tried remotely installing the albersusa package (also installed remotes package beforehand), but I'm still getting the error about the dependencies:

ERROR: dependencies ‘rgeos’, ‘rgdal’ are not available for package ‘albersusa’

In the previous module I was able to use the tigris package workaround. Is there a similar solution here that replaces the counties_sf function in the albersusa package?

David Keyes

David Keyes Founder

January 25, 2024

Yes, if you run tigris::counties() you should get an object that is basically the same (the column names are different, but the geometry column is identical). Let me know if that helps!

Kendall Beals

Kendall Beals

January 25, 2024

Thank you, it worked!