library(tidyverse)
library(routes)
library(here)
start <- "Corvallis, OR"
end <- "Portland, OR"

Get coordinates

route_lat_lon <- get_route(start, end)

Checks

Interactive with leaflet:

library(leaflet)
leaflet() %>% 
  addTiles() %>% 
  addPolylines(~ lon, ~ lat, data = route_lat_lon)

Static with ggmap:

library(ggmap)
bbox <- with(route_lat_lon, 
  c(left = min(lon), bottom = min(lat), 
    right = max(lon), top = max(lat)))

map <- get_stamenmap(bbox, zoom = 9, 
  maptype = "toner-hybrid", source = "stamen", force = TRUE)
ggmap(map) +
  geom_path(data = route_lat_lon, color = "#377EB8") +
  theme_void()

Save for later:

route_lat_lon %>% 
  write_rds(here("oregon", "data", "route_coords.rds")) %>% 
  write_csv(here("oregon", "data", "route_coords.csv"))


cwickham/routes documentation built on Nov. 4, 2019, 9:34 a.m.