DiagrammeR (version 0.9.2)

add_balanced_tree: Add a balanced tree to the graph

Description

With a graph object of class dgr_graph, add a balanced tree to the graph.

Usage

add_balanced_tree(graph, k, h, type = NULL, label = TRUE, rel = NULL)

Arguments

graph

a graph object of class dgr_graph.

k

the branching factor for the tree.

h

the height of the tree.

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 tree.

Value

a graph object of class dgr_graph.

Examples

Run this code
# NOT RUN {
# Create a new graph and
# add 2 different types of
# balanced trees of height
# 2 (branching twice) and
# different branching ratios
graph <-
  create_graph() %>%
  add_balanced_tree(
    k = 2,
    h = 2,
    type = "binary") %>%
  add_balanced_tree(
    k = 3,
    h = 2,
    type = "tertiary")

# Get some node information
# from this graph
node_info(graph) %>%
  head(5)
#>   id   type label deg indeg outdeg loops
#> 1  1 binary     1   2     0      2     0
#> 2  2 binary     2   3     1      2     0
#> 3  3 binary     3   3     1      2     0
#> 4  4 binary     4   1     1      0     0
#> 5  5 binary     5   1     1      0     0
# }

Run the code above in your browser using DataLab