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
already in the graph (using direction = "to").
Optionally, set node type and edge rel
values for all the new nodes and edges created,
respectively.
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().
Selections of nodes can also be performed using
the following traversal functions:
(trav_...):
trav_out(), trav_in(),
trav_both(), trav_in_node(),
trav_out_node().
add_n_nodes_ws(graph, n, direction = NULL, type = NULL, label = NULL, rel = NULL, node_aes = NULL, edge_aes = NULL, node_data = NULL, edge_data = 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 |
| type | an optional character vector that provides group identifiers for the nodes to be added. |
| label | an optional character object that describes the nodes to be added. |
| rel | an optional string to apply a
|
| node_aes | an optional list of named vectors
comprising node aesthetic attributes. The helper
function |
| edge_aes | an optional list of named vectors
comprising edge aesthetic attributes. The helper
function |
| node_data | an optional list of named vectors
comprising node data attributes. The helper
function |
| edge_data | an optional list of named vectors
comprising edge data attributes. The helper
function |
a graph object of class dgr_graph.
# 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(n = 1) %>% select_last_nodes_created() %>% add_n_nodes_ws( n = 5, direction = "from") # Get the graph's nodes graph %>% get_node_ids()#> [1] 1 2 3 4 5 6#> [1] "1->2" "1->3" "1->4" "1->5" "1->6"#> "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(n = 1) %>% select_last_nodes_created() %>% add_n_nodes_ws( n = 5, direction = "to") # Get the graph's nodes graph %>% get_node_ids()#> [1] 1 2 3 4 5 6#> [1] "2->1" "3->1" "4->1" "5->1" "6->1"#> "2->1" "3->1" "4->1" "5->1" "6->1"