add_edge_clone {DiagrammeR} | R Documentation |
Add a new edge to a graph object of
class dgr_graph
which is a clones of an edge
already in the graph. All edge attributes are
preserved.
add_edge_clone(graph, edge, from, to)
graph |
a graph object of class
|
edge |
an edge ID corresponding to the graph edge to be cloned. |
from |
the outgoing node from which the edge is connected. |
to |
the incoming nodes to which each edge is connected. |
a graph object of class dgr_graph
.
# Create a graph with a path of # 2 nodes; supply a common `rel` # edge attribute for all edges # in this path and then add a # `color` edge attribute graph <- create_graph() %>% add_path( n = 2, rel = "a") %>% select_last_edges_created() %>% set_edge_attrs( edge_attr = color, values = "steelblue") %>% clear_selection() # Display the graph's internal # edge data frame graph %>% get_edge_df() #> id from to rel color #> 1 1 1 2 a steelblue # Create a new node (will have # node ID of `3`) and then # create an edge between it and # node `1` while reusing the edge # attributes of edge `1` -> `2` # (edge ID `1`) graph_2 <- graph %>% add_node() %>% add_edge_clone( edge = 1, from = 3, to = 1) # Display the graph's internal # edge data frame graph_2 %>% get_edge_df() #> id from to rel color #> 1 1 1 2 a steelblue #> 2 2 3 1 a steelblue # The same change can be performed # with some helper functions in the # `add_edge_clone()` function call graph_3 <- graph %>% add_node() %>% add_edge_clone( edge = get_last_edges_created(.), from = get_last_nodes_created(.), to = 1) # Display the graph's internal # edge data frame graph_3 %>% get_edge_df() #> id from to rel color #> 1 1 1 2 a steelblue #> 2 2 3 1 a steelblue