Add a node to an existing graph object

Share:

Description

With a graph object of class dgr_graph, add a new node of a specified type to extant nodes within the graph.

Usage

1
2
add_node(graph, type = NULL, label = TRUE, from = NULL, to = NULL,
  node = NULL)

Arguments

graph

a graph object of class dgr_graph that is created using create_graph.

type

an optional string that describes the entity type for the node to be added.

label

a character object for supplying an optional label to the node. Setting to TRUE ascribes the node ID to the label. Setting to FALSE yields a blank label.

from

an optional vector containing node IDs from which edges will be directed to the new node.

to

an optional vector containing node IDs to which edges will be directed from the new node.

node

an optional node ID for the newly connected node. If no value is provided, a node ID will assigned as a monotonically increasing integer.

Value

a graph object of class dgr_graph.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
# Create an empty graph
graph <- create_graph()

# Add two nodes
graph <- add_node(graph)
graph <- add_node(graph)

get_nodes(graph)
#> [1] "1" "2"

# Add a node with 'type' defined
graph <- add_node(graph, type = "person")

get_node_df(graph)
#>   nodes   type label
#> 1     1            1
#> 2     2            2
#> 3     3 person     3

Want to suggest features or report bugs for rdrr.io? Use the GitHub issue tracker.