| create_undirected_graph | R Documentation |
Convert a directed graph to an undirected graph by normalizing edges and aggregating duplicate connections.
create_undirected_graph(graph_df, by = NULL, ...)
graph_df |
A data frame representing a directed graph including columns:
|
by |
Link characteristics to preserve/not aggregate across, passed as a one-sided formula or character vector of column names. Typically this includes attributes like mode, type, or capacity to ensure that only edges with the same characteristics are aggregated. |
... |
Arguments passed to |
This function converts a directed graph to an undirected graph by:
Normalizing edge directions so that from < to for all edges
Collapsing duplicate edges (same from and to nodes)
For spatial/identifier columns (edge, FX, FY, TX, TY),
taking the first value from duplicates
For aggregation columns, collap() will be applied.
A data frame representing an undirected graph with:
edge - Edge identifier (first value from duplicates)
from - Starting node ID (normalized to be < to)
to - Ending node ID (normalized to be > from)
FX - Starting node X-coordinate (first value from duplicates)
FY - Starting node Y-coordinate (first value from duplicates)
TX - Ending node X-coordinate (first value from duplicates)
TY - Ending node Y-coordinate (first value from duplicates)
Aggregated columns
library(flownet)
# Convert segments to graph and make undirected
graph <- africa_segments |>
linestrings_from_graph() |>
linestrings_to_graph()
graph_undir <- create_undirected_graph(graph, FUN = "fsum")
# Fewer edges after removing directional duplicates
c(directed = nrow(graph), undirected = nrow(graph_undir))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.