Skip to content
R for the Rest of Us Logo

sf for Simple Features (01_04)

This lesson is locked

Get access to all lessons in this 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 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 19, 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?

Tyler Kelly

Tyler Kelly

March 5, 2022

I am having the same issue. The county polygons are not showing up.

Charlie Hadley

Charlie Hadley

March 7, 2022

Hello Tyler. Could you update RStudio and see if this resolves the issue?

Tyler Kelly

Tyler Kelly

March 11, 2022

Hi Charlie, sadly no it hasn't.

Charlie Hadley

Charlie Hadley

March 7, 2022

Hi Latif, did this issue resolve by updating RStudio?

Ochiagha Ananaba

Ochiagha Ananaba

June 17, 2022

I have the same issues where base map is showing but not the boundaries. I am using R version 4.1.0 (2021-05-18) -- "Camp Pontanezen"

Ochiagha Ananaba

Ochiagha Ananaba

June 17, 2022

Included mapviewOptions(fgb = FALSE) in my code and it worked

Charlie Hadley

Charlie Hadley

June 20, 2022

Hello! Sorry this isn't working for you, there are some known issue with {mapview}. Could you try the following?

  • install.packages("remotes")
  • remotes::install_github('r-spatial/leafem')
  • remotes::install_github("r-spatial/mapview")
  • Try making the maps again

To give you some context, the {mapview} package is developed on GitHub and "the known issue" is this page - https://github.com/r-spatial/mapview/issues/413.

Please let me know if this doesn't work.

Cheers,

Charlie

Oscar Tetteh

Oscar Tetteh

March 29, 2023

Hi

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

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

David Keyes

David Keyes

March 29, 2023

Can you share your full code please?

Hannah Ridenour LaFrance

Hannah Ridenour LaFrance

July 17, 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

David Keyes

David Keyes

July 17, 2023

You should be able to install it with this code:

remotes::install_git("https://git.rud.is/hrbrmstr/albersusa.git")

You'll need to install the remotes package using install.packages("remotes") first (if you don't already have it installed). Let me know if that works!

Hannah Ridenour LaFrance

Hannah Ridenour LaFrance

July 18, 2023

Success! Turns out my issue was not having git installed...I got a new laptop a few months ago and have slowly been rediscovering all the setup items I need to redo. I'm very grateful to the archived R in 3 Months videos to refer back to in these moments!