add_node {DiagrammeR} | R Documentation

## 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, 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

    ## Not run:
    # 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

    ## End(Not run)

[Package DiagrammeR version 0.8.2 Index]