create_random_graph {DiagrammeR}R Documentation

Create a randomized graph

Description

Create a graph of up to n nodes with randomized edge assignments.

Usage

create_random_graph(n, m, directed = FALSE, fully_connected = FALSE,
  display_labels = TRUE, set_seed = NULL, node_id = NULL)

Arguments

n

the number of nodes to use in the random graph.

m

the number of edges to use in the random graph.

directed

an option for whether the random graph should be undirected (default) or directed.

fully_connected

should the graph be fully connected (i.e., no free nodes).

display_labels

display node labels.

set_seed

supplying a value sets a random seed of the Mersenne-Twister implementation.

node_id

an optional vector of unique node ID values to apply to the randomized graph. The length of the vector should ideally correspond to the value supplied in n; vectors longer than the length of n will be truncated.

Examples

# Create a random, directed graph with 50 nodes
# and 75 edges
random_graph_directed <-
  create_random_graph(
    n = 50,
    m = 75,
    directed = TRUE)

# Create a random, undirected graph that's
# fully connected
random_graph_undirected <-
  create_random_graph(
    n = 30,
    m = 30,
    fully_connected = TRUE)

# Create a directed graph with a seed set so that
# it's reproducible
directed_graph <-
  create_random_graph(
    n = 15,
    m = 34,
    set_seed = 50)

# Create a directed, random graph with a supplied
# set of node IDs
random_directed_graph_letters <-
  create_random_graph(
    n = 10,
    m = 20,
    directed = TRUE,
    node_id = LETTERS)

[Package DiagrammeR version 0.8.4 Index]