#' Visualize the optimal route
#'
#' Plots the optimal route using ggplot2
#'
#' @param epath igraph.es object containing the route
#' @param graph tbl_graph object with the network used to calculate the
#' route
#'
#' @return ggplot of optimal route within the network
#'
visualize_path <- function(epath, graph){
library(ggplot2)
library(dplyr)
path_graph <- graph %>%
subgraph.edges(eids = epath %>% unlist()) %>%
as_tbl_graph()
ggplot() +
geom_sf(data = graph %>% activate(edges) %>% as_tibble() %>% st_as_sf(), col = 'darkgrey') +
geom_sf(data = graph %>% activate(nodes) %>% as_tibble() %>% st_as_sf(), col = 'darkgrey', size = 0.5) +
geom_sf(data = path_graph %>% activate(edges) %>% as_tibble() %>% st_as_sf(), lwd = 1, col = 'firebrick') #+
#geom_sf(data = path_graph %>% activate(nodes) %>% filter(nodeID %in% c(from_node, to_node)) %>% as_tibble() %>% st_as_sf(), size = 2)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.