library(tidyverse) library(routes) library(here)
start <- "Corvallis, OR" end <- "Portland, OR"
route_lat_lon <- get_route(start, end)
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"))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.