Learn R Programming

DiagrammeR (version 0.8.4)

add_cycle: Add a cycle of nodes to the graph

Description

With a graph object of class dgr_graph, add a node cycle to the graph.

Usage

add_cycle(graph, n, type = NULL, label = TRUE, rel = NULL, nodes = NULL)

Arguments

graph
a graph object of class dgr_graph that is created using create_graph.
n
the number of nodes comprising the cycle.
type
an optional string that describes the entity type for the nodes to be added.
label
either a vector object of length n that provides optional labels for the new nodes, or, a boolean value where setting to TRUE ascribes node IDs to the label and FALSE yields a blank label.
rel
an optional string for providing a relationship label to all new edges created in the node cycle.
nodes
an optional vector of node IDs of length n for the newly created nodes. If nothing is provided, node IDs will assigned as monotonically increasing integers.

Value

a graph object of class dgr_graph.

Examples

Run this code
library(magrittr)

# Create a new graph and add a cycle of nodes to it
graph <-
  create_graph() %>%
  add_cycle(6)

# Get node information from this graph
node_info(graph)
#>   node label type deg indeg outdeg loops
#> 1    1     1        2     1      1     0
#> 2    2     2        2     1      1     0
#> 3    3     3        2     1      1     0
#> 4    4     4        2     1      1     0
#> 5    5     5        2     1      1     0
#> 6    6     6        2     1      1     0

Run the code above in your browser using DataLab