To an existing graph object, add a graph built according to the Barabasi-Albert model, which uses preferential attachment in its stochastic algorithm.
add_pa_graph(
graph,
n,
m = NULL,
power = 1,
out_dist = NULL,
use_total_degree = FALSE,
zero_appeal = 1,
algo = "psumtree",
type = NULL,
label = TRUE,
rel = NULL,
node_aes = NULL,
edge_aes = NULL,
node_data = NULL,
edge_data = NULL,
set_seed = NULL
)
A graph object of class dgr_graph
.
The number of nodes comprising the preferential attachment graph.
The number of edges to add in each time step.
The power of the preferential attachment. The default value of
1
indicates a linear preferential attachment.
A numeric vector that provides the distribution of the number of edges to add in each time step.
A logical value (default is TRUE
) that governs
whether the total degree should be used for calculating the citation
probability. If FALSE
, the indegree is used.
A measure of the attractiveness of the nodes with no adjacent edges.
The algorithm to use to generate the graph. The available options
are psumtree
, psumtree-multiple
, and bag
. With the psumtree
algorithm, a partial prefix-sum tree is used to to create the graph. Any
values for power
and zero_appeal
can be provided and this algorithm
never generates multiple edges. The psumtree-multiple
algorithm also uses
a partial prefix-sum tree but the difference here is that multiple edges
are allowed. The bag
algorithm places the node IDs into a bag as many
times as their in-degree (plus once more). The required number of cited
nodes are drawn from the bag with replacement. Multiple edges may be
produced using this method (it is not disallowed).
An optional string that describes the entity type for all the nodes to be added.
A logical value where setting to TRUE
ascribes node IDs to the
label and FALSE
yields a blank label.
An optional string for providing a relationship label to all edges to be added.
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
).
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
).
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.
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.
Supplying a value sets a random seed of the
Mersenne-Twister
implementation.
# Create an undirected PA
# graph with 100 nodes, adding
# 2 edges at every time step
pa_graph <-
create_graph(
directed = FALSE) %>%
add_pa_graph(
n = 100,
m = 1)
# Get a count of nodes
pa_graph %>% count_nodes()
# Get a count of edges
pa_graph %>% count_edges()
Run the code above in your browser using DataLab