add_node: Add a node to an existing graph object

Description Usage Arguments Value Examples

View source: R/add_node.R

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
add_node(graph, type = NULL, label = NULL, from = NULL, to = NULL, ...)

Arguments

graph

a graph object of class dgr_graph.

type

an optional character object that acts as a group identifier for the node to be added.

label

an optional character object that describes the node.

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.

...

one or more optional, single value vectors for supplying node attributes to the new node.

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
19
20
21
22
23
24
25
26
27
28
29
30
# Create an empty graph and add 2 nodes by using
# the `add_node()` function twice
graph <-
  create_graph() %>%
  add_node() %>%
  add_node()

# Get a count of all nodes
# in the graph
node_count(graph)
#> [1] 2

# The nodes added were given
# ID values `1` and `2`
get_node_ids(graph)
#> [1] 1 2

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

# View the graph's internal
# node data frame (ndf)
get_node_df(graph)
#>   id   type label
#> 1  1   <NA>  <NA>
#> 2  2   <NA>  <NA>
#> 3  3 person  <NA>

DiagrammeR documentation built on Aug. 21, 2017, 5:03 p.m.