add_node_clones_ws: Add clones of a selection of nodes

Description Usage Arguments Details Value See Also Examples

View source: R/add_node_clones_ws.R

Description

Add new nodes to a graph object of class dgr_graph which are clones of nodes in an active selection of nodes. All node attributes are preserved except for the node label attribute (to maintain the uniqueness of non-NA node label values). A vector of node label can be provided to bind new labels to the cloned nodes.

Usage

1
add_node_clones_ws(graph, add_edges = FALSE, direction = NULL, label = NULL)

Arguments

graph

A graph object of class dgr_graph.

add_edges

An option for whether to add edges from the selected nodes to each of their clones, or, in the opposite direction.

direction

Using from will create new edges from existing nodes to the new, cloned nodes. The to option will create new edges directed toward the existing nodes.

label

An optional vector of node label values. The vector length should correspond to the number of nodes in the active selection of nodes.

Details

This function makes use of an active selection of nodes (and the function ending with _ws hints at this).

Selections of nodes can be performed using the following node selection (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 (trav_*()) functions: trav_out(), trav_in(), trav_both(), trav_out_node(), trav_in_node(), trav_out_until(), or trav_in_until().

Value

A graph object of class dgr_graph.

See Also

Other Node creation and removal: add_n_node_clones(), add_n_nodes_ws(), add_n_nodes(), add_node_df(), add_nodes_from_df_cols(), add_nodes_from_table(), add_node(), colorize_node_attrs(), copy_node_attrs(), create_node_df(), delete_nodes_ws(), delete_node(), drop_node_attrs(), join_node_attrs(), layout_nodes_w_string(), mutate_node_attrs_ws(), mutate_node_attrs(), node_data(), recode_node_attrs(), rename_node_attrs(), rescale_node_attrs(), set_node_attr_to_display(), set_node_attr_w_fcn(), set_node_attrs_ws(), set_node_attrs(), set_node_position()

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# Create a graph with a path of
# nodes; supply `label`, `type`,
# and `value` node attributes,
# and select the created nodes
graph <-
  create_graph() %>%
  add_path(
    n = 3,
    label = c("d", "g", "r"),
    type = c("a", "b", "c")) %>%
  select_last_nodes_created()

# Display the graph's internal
# node data frame
graph %>% get_node_df()

# Create clones of all nodes
# in the selection but assign
# new node label values
# (leaving `label` as NULL
# yields NA values)
graph <-
  graph %>%
  add_node_clones_ws(
    label = c("a", "b", "v"))

# Display the graph's internal
# node data frame: nodes `4`,
# `5`, and `6` are clones of
# `1`, `2`, and `3`
graph %>% get_node_df()

# Select the last nodes
# created (`4`, `5`, and `6`)
# and clone those nodes and
# their attributes while
# creating new edges between
# the new and existing nodes
graph <-
  graph %>%
  select_last_nodes_created() %>%
  add_node_clones_ws(
    add_edges = TRUE,
    direction = "to",
    label = c("t", "z", "s"))

# Display the graph's internal
# edge data frame; there are
# edges between the selected
# nodes and their clones
graph %>% get_edge_df()

DiagrammeR documentation built on July 2, 2020, 3:19 a.m.