Skip to content
R for the Rest of Us Logo

Mapping with R

Turning Data Frames Into sf Objects

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.

View code shown in video
library(tidyverse)
library(sf)

portland_corners_csv <-
  read_csv("https://raw.githubusercontent.com/rfortherestofus/mapping-with-r-v2/refs/heads/main/data/portland_corners.csv")

portland_corners_csv

portland_corners_sf <-
  portland_corners_csv |>
  st_as_sf(
    coords = c("longitude", "latitude"),
    crs = 4326
  )


portland_corners_sf |>
  mapview::mapview()

Your Turn

  1. Download this CSV of traffic signal data for the city of Portland

  2. Import the CSV and turn it into an sf object using st_as_sf()

  3. Run mapview::mapview() to ensure you imported it correctly

Learn More

Chapter 3 of the book Spatial Statistics for Data Science: Theory and Practice with R covers turning data frames into sf objects.

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

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