DiagrammeR (version 1.0.0)

add_gnp_graph: 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, type = NULL, label = TRUE,
  rel = NULL, node_aes = NULL, edge_aes = NULL, node_data = NULL,
  edge_data = NULL, set_seed = NULL)

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.

type

an optional string that describes the entity type for all the nodes to be added.

label

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 edges 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).

edge_aes

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

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.

edge_data

an optional list of named vectors comprising edge data attributes. The helper function edge_data() is strongly recommended for use here as it helps bind data specifically to the created edges.

set_seed

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

Examples

Run this code
# NOT RUN {
# 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 %>%
  count_nodes()

# Get a count of edges
gnp_graph %>%
  count_edges()
# }

Run the code above in your browser using DataCamp Workspace