Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

add_n_nodes

Add one or several unconnected nodes to the graph


Description

Add n new nodes to a graph object of class dgr_graph. Optionally, set node type values for the new nodes.

Usage

add_n_nodes(
  graph,
  n,
  type = NULL,
  label = NULL,
  node_aes = NULL,
  node_data = NULL
)

Arguments

graph

A graph object of class dgr_graph.

n

The number of new nodes to add to the graph.

type

An optional character vector that provides group identifiers for the nodes to be added.

label

An optional character object that describes the nodes to be added.

node_aes

An optional list of named vectors comprising node aesthetic attributes. The helper function node_aes() is strongly recommended for use here as it contains arguments for each of the accepted node aesthetic attributes (e.g., shape, style, color, fillcolor).

node_data

An optional list of named vectors comprising node data attributes. The helper function node_data() is strongly recommended for use here as it helps bind data specifically to the created nodes.

Value

A graph object of class dgr_graph.

See Also

Examples

# Create an empty graph and
# add 5 nodes; these nodes
# will be assigned ID values
# from `1` to `5`
graph <-
  create_graph() %>%
  add_n_nodes(n = 5)

# Get the graph's node IDs
graph %>% get_node_ids()

DiagrammeR

Graph/Network Visualization

v1.0.6.1
MIT + file LICENSE
Authors
Richard Iannone [aut, cre] (<https://orcid.org/0000-0003-3925-190X>)
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.