Learn R Programming

DiagrammeR (version 0.7)

add_node: Add a node to an existing graph object

Description

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

Usage

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

Arguments

graph
a graph object of class dgr_graph that is created using create_graph.
node
a node ID for the newly connected 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.
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.
type
an optional string that describes the entity type for the node to be added.
...
one or more vectors pertaining to node attributes.

Value

  • a graph object of class dgr_graph.

Examples

Run this code
# Create an empty graph
graph <- create_graph()

# Add two nodes
graph <- add_node(graph, node = "a")
graph <- add_node(graph, node = "b")

Run the code above in your browser using DataLab