create_subgraph_ws {DiagrammeR} | R Documentation |
Create a subgraph based on a
selection of nodes or edges stored in the graph
object. Selections of nodes can be performed using
the following select_...
functions:
select_nodes()
,
select_last_nodes_created()
,
select_nodes_by_degree()
,
select_nodes_by_id()
, or
select_nodes_in_neighborhood()
.
Alternatively, selections of edges can be made
with these functions: select_edges()
,
select_last_edge()
, or
select_edges_by_node_id()
. Selections of
nodes or edges can also be performed using
any of the traversal functions (trav_...
).
create_subgraph_ws(graph)
graph |
a graph object of class
|
a graph object of class dgr_graph
.
# Create a node data frame (ndf) ndf <- create_node_df( n = 6, value = c(3.5, 2.6, 9.4, 2.7, 5.2, 2.1)) # Create an edge data frame (edf) edf <- create_edge_df( from = c(1, 2, 4, 5, 2, 6), to = c(2, 4, 1, 3, 5, 5)) # Create a graph graph <- create_graph( nodes_df = ndf, edges_df = edf) # Create a selection of nodes, this selects # nodes `1`, `3`, and `5` graph <- graph %>% select_nodes( conditions = value > 3) # Create a subgraph based on the selection subgraph <- create_subgraph_ws(graph) # Display the graph's node data frame get_node_df(subgraph) #> id type label value #> 1 1 <NA> <NA> 3.5 #> 2 3 <NA> <NA> 9.4 #> 3 5 <NA> <NA> 5.2 # Display the graph's edge data frame get_edge_df(subgraph) #> id from to rel #> 1 4 5 3 <NA>