add_n_nodes_ws {DiagrammeR} | R Documentation |
Add n new nodes to or from one or more
nodes available as a selection in a graph object of
class dgr_graph
. New graph edges will all
move either from the nodes in the selection toward
the newly created nodes (with the option
direction = "from"
), or to the selected nodes
alredy in the graph (using direction = "to"
).
Optionally, set node type
and edge rel
values for all the new nodes and edges created,
respectively.
add_n_nodes_ws(graph, n, direction = NULL, set_node_type = NULL, set_edge_rel = NULL)
graph |
a graph object of class
|
n |
the number of new nodes to attach as successor nodes to the nodes in the selection. |
direction |
using |
set_node_type |
an optional string to apply a
|
set_edge_rel |
an optional string to apply a
|
a graph object of class dgr_graph
.
library(magrittr) # Create an empty graph, add a node to it, select # that node, and then add 5 more nodes to the graph # with edges from the original node to all of the # new nodes graph <- create_graph() %>% add_n_nodes(1) %>% select_last_node %>% add_n_nodes_ws(5, "from") # Get the graph's nodes graph %>% get_nodes #> [1] "1" "2" "3" "4" "5" "6" # Get the graph's edges graph %>% get_edges #> "1 -> 2" "1 -> 3" "1 -> 4" "1 -> 5" "1 -> 6" # Create an empty graph, add a node to it, select # that node, and then add 5 more nodes to the graph # with edges toward the original node from all of # the new nodes graph <- create_graph() %>% add_n_nodes(1) %>% select_last_node %>% add_n_nodes_ws(5, "to") # Get the graph's nodes graph %>% get_nodes #> [1] "1" "2" "3" "4" "5" "6" # Get the graph's edges graph %>% get_edges #> "2 -> 1" "3 -> 1" "4 -> 1" "5 -> 1" "6 -> 1"