add_gnp_graph {DiagrammeR}R Documentation

Add a G(n, p) Erdos-Renyi graph

Description

To an existing graph object, add a graph built according to the Erdos-Renyi G(n, p) model, which uses a constant probability when creating edges.

Usage

add_gnp_graph(graph, n, p, loops = FALSE)

Arguments

graph

a graph object of class dgr_graph.

n

the number of nodes comprising the generated graph.

p

the probability of creating an edge between two arbitrary nodes.

loops

a logical value (default is FALSE) that governs whether loops are allowed to be created.

Examples

# Create an undirected GNP
# graph with 100 nodes using
# a probability value of 0.05
gnp_graph <-
  create_graph(
    directed = FALSE) %>%
  add_gnp_graph(
    n = 100,
    p = 0.05)

# Get a count of nodes
gnp_graph %>% node_count()
#> [1] 100

# Get a count of edges
gnp_graph %>% edge_count()
#> [1] 216

[Package DiagrammeR version 0.9.2 Index]