add_n_node_clones: Add one or several clones of an existing node to the graph

View source: R/add_n_node_clones.R

add_n_node_clonesR Documentation

Add one or several clones of an existing node to the graph


Add n new nodes to a graph object of class dgr_graph which are clones of a node already in the graph. 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.


add_n_node_clones(graph, n, node, label = NULL)



A graph object of class dgr_graph.


The number of node clones to add to the graph.


A node ID corresponding to the graph node to be cloned.


An optional vector of node label values. The vector length should correspond to the value set for n.


A graph object of class dgr_graph.

See Also

Other Node creation and removal: add_n_nodes_ws(), add_n_nodes(), add_node_clones_ws(), 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()


# Create a graph with a path of
# nodes; supply `label`, `type`,
# and `value` node attributes
graph <-
  create_graph() %>%
    n = 3,
    label = c("d", "g", "r"),
    type = c("a", "b", "c"))

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

# Create 3 clones of node `1`
# but assign new node label
# values (leaving `label` as
# NULL yields NA values)
graph <-
  graph %>%
    n = 3,
    node = 1,
    label = c("x", "y", "z"))

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

DiagrammeR documentation built on March 18, 2022, 7:11 p.m.