#' Subset a graph based on optimal route
#'
#' Subsets a graph based on optimal routes that can be used to e.g. calculate
#' summary statistics.
#'
#' @param graph tbl_graph object with the network used to calculate the
#' route
#' @param epath igraph.es object containing the route
#'
#' @return sf object with a subset of the network based on the route
#'
subset_edges_as_sf <- function(graph, epath){
graph %>%
subgraph.edges(eids = epath %>% unlist()) %>%
as_tbl_graph() %>%
activate(edges) %>%
as_tibble() %>%
st_as_sf()
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.