### Example Usage Source: https://tidygraph.data-imaginist.com/reference/map_local.html Demonstrates how to use map_local_dbl to smooth out values over a neighborhood by calculating the mean of node values within a specified order. ```APIDOC ## Example ```R # Smooth out values over a neighborhood create_notable('meredith') %>% mutate(value = rpois(graph_order(), 5)) %>% mutate(value_smooth = map_local_dbl(order = 2, .f = function(neighborhood, ...) { mean(as_tibble(neighborhood, active = 'nodes')$value) })) ``` ``` -------------------------------- ### Install tidygraph Development Version Source: https://tidygraph.data-imaginist.com/index.html Installs the development version of the tidygraph package from GitHub using the 'pak' package manager. This is an alternative to installing from CRAN. ```r # install.packages('pak') pak::pak('thomasp85/tidygraph') ``` -------------------------------- ### Example of Play Islands Graph Creation Source: https://tidygraph.data-imaginist.com/reference/component_games.html Demonstrates how to create and plot a graph using the play_islands function. This is useful for visualizing networks with distinct clusters. ```r plot(play_islands(4, 10, 0.7, 3)) ``` -------------------------------- ### Plotting a Bipartite Graph Source: https://tidygraph.data-imaginist.com/reference/type_games.html This example demonstrates how to create and plot a bipartite graph using the play_bipartite function. It specifies the number of nodes for each partition and the probability of an edge occurring between them. ```R plot(play_bipartite(20, 30, 0.4)) ``` -------------------------------- ### Example: Find Root and Leaf Nodes in a Tree Source: https://tidygraph.data-imaginist.com/reference/node_types.html Demonstrates how to identify root and leaf nodes in a tree structure using `node_is_root()` and `node_is_leaf()`. Requires the `dplyr` and `tidygraph` packages. ```R # Find the root and leafs in a tree create_tree(40, 2) %>% mutate(root = node_is_root(), leaf = node_is_leaf()) ``` -------------------------------- ### Example of Erdos-Renyi Graph Generation Source: https://tidygraph.data-imaginist.com/reference/sampling_games.html Demonstrates how to generate an Erdos-Renyi graph with 20 nodes and an edge probability of 0.3. Note that `play_erdos_renyi` is deprecated and `play_gnp` should be used instead. ```R plot(play_erdos_renyi(20, 0.3)) ``` -------------------------------- ### Sort Graph by Topological Order Source: https://tidygraph.data-imaginist.com/reference/node_topology.html Demonstrates sorting a graph based on its topological order. This example creates a tree, shuffles its nodes, and then reorders them according to their topological sort. Requires the `tidygraph` package. ```R # Sort a graph based on its topological order create_tree(10, 2) %>% arrange(sample(graph_order())) %>% mutate(old_ind = seq_len(graph_order())) %>% arrange(node_topo_order()) ``` -------------------------------- ### Add Random Integer Accumulation using map_dfs_int Source: https://tidygraph.data-imaginist.com/reference/map_dfs.html This example demonstrates using `map_dfs_int` to add a random integer to the accumulated value from the parent node. It shows how to access the path information to get the last value. ```R create_tree(40, children = 3, directed = TRUE) %>% mutate(child_acc = map_dfs_int(node_is_root(), .f = function(node, path, ...) { last_val <- if (nrow(path) == 0) 0L else tail(unlist(path$result), 1) last_val + sample(1:10, 1) })) ``` -------------------------------- ### Example of graph_join Source: https://tidygraph.data-imaginist.com/reference/graph_join.html Demonstrates how to use graph_join to combine two tbl_graph objects based on common node attributes. Node and edge data are merged, and edges are updated to reflect the new node indices. ```r gr1 <- create_notable('bull') %>% activate(nodes) %>% mutate(name = letters[1:5]) gr2 <- create_ring(10) %>% activate(nodes) %>% mutate(name = letters[4:13]) gr1 %>% graph_join(gr2) #> Joining with `by = join_by(name)` #> # A tbl_graph: 13 nodes and 15 edges #> # #> # A directed acyclic simple graph with 1 component #> # #> # Node Data: 13 × 1 (active) #> name #> #> 1 a #> 2 b #> 3 c #> 4 d #> 5 e #> 6 f #> 7 g #> 8 h #> 9 i #> 10 j #> 11 k #> 12 l #> 13 m #> # #> # Edge Data: 15 × 2 #> from to #> #> 1 1 2 #> 2 1 3 #> 3 2 3 #> # ℹ 12 more rows ``` -------------------------------- ### Reroute Edges with Subset Source: https://tidygraph.data-imaginist.com/reference/reroute.html This example shows how to reroute edges where the destination node ('to') is greater than 10, changing their 'from' node to 1. This utilizes the 'subset' argument to selectively apply the rerouting. ```r create_notable('meredith') %>% activate(edges) %>% reroute(from = 1, subset = to > 10) ``` -------------------------------- ### Calculate distance to the center node Source: https://tidygraph.data-imaginist.com/reference/pair_measures.html This example demonstrates calculating the distance from all nodes to the center node in a graph. It uses `node_distance_to()` and `node_is_center()` within the `tidygraph` framework. ```R # Calculate the distance to the center node create_notable('meredith') %>% mutate(dist_to_center = node_distance_to(node_is_center())) #> # A tbl_graph: 70 nodes and 140 edges #> # #> # An undirected simple graph with 1 component #> # #> # Node Data: 70 × 1 (active) #> dist_to_center #> #> 1 1 #> 2 1 #> 3 1 #> 4 5 #> 5 6 #> 6 6 #> 7 3 #> 8 7 #> 9 7 #> 10 4 #> # ℹ 60 more rows #> # #> # Edge Data: 140 × 2 #> from to #> #> 1 1 5 #> 2 1 6 #> 3 1 7 #> # ℹ 137 more rows ``` -------------------------------- ### .G() Source: https://tidygraph.data-imaginist.com/reference/context_accessors.html Get the tbl_graph you're currently working on. ```APIDOC ## .G() ### Description Get the tbl_graph you're currently working on. ### Value A `tbl_graph` object. ### Example ```R create_notable('bull') %>% activate(nodes) %>% mutate(centrality = centrality_power()) %>% activate(edges) %>% mutate(mean_centrality = (.G()$nodes$centrality[from] + .G()$nodes$centrality[to])/2) ``` ``` -------------------------------- ### Calculate Edge Rank Using Eulerian Path Source: https://tidygraph.data-imaginist.com/reference/edge_rank.html This example demonstrates how to calculate the edge rank for a graph using the `edge_rank_eulerian` function. The resulting rank is added as a new attribute to the edges. ```R graph <- create_notable('meredith') %>% activate(edges) %>% mutate(rank = edge_rank_eulerian()) ``` -------------------------------- ### Smooth Node Values Using Local Neighborhoods Source: https://tidygraph.data-imaginist.com/reference/map_local.html This example demonstrates smoothing node values by calculating the mean of a 'value' attribute within a node's neighborhood. It uses map_local_dbl to ensure the result is a double vector. ```R create_notable('meredith') %>% mutate(value = rpois(graph_order(), 5)) %>% mutate(value_smooth = map_local_dbl(order = 2, .f = function(neighborhood, ...) { mean(as_tibble(neighborhood, active = 'nodes')$value) })) ``` -------------------------------- ### Calculating edge attributes based on node attributes Source: https://tidygraph.data-imaginist.com/reference/context_accessors.html This example demonstrates how to use context accessors to compute edge attributes based on node attributes. It first calculates node centrality and then uses `.N()` to access the centrality values of the 'from' and 'to' nodes to compute the mean centrality for each edge. ```R create_notable('bull') %>% activate(nodes) %>% mutate(centrality = centrality_power()) %>% activate(edges) %>% mutate(mean_centrality = (.N()$centrality[from] + .N()$centrality[to])/2) ``` -------------------------------- ### Get neighborhood members of each graph node Source: https://tidygraph.data-imaginist.com/reference/local_graph.html This snippet demonstrates how to get all neighbors of each node in a graph using `local_members` with a minimum distance of 1. It activates node data and mutates a new column with the neighborhood information. ```R create_notable('chvatal') %>/ activate(nodes) %>/ mutate(neighborhood = local_members(mindist = 1)) ``` -------------------------------- ### .N() Source: https://tidygraph.data-imaginist.com/reference/context_accessors.html Get the nodes data from the graph you're currently working on. ```APIDOC ## .N(focused = TRUE) ### Description Get the nodes data from the graph you're currently working on. ### Arguments * `focused` (logical) - Should only the attributes of the currently focused nodes be returned. Defaults to TRUE. ### Value A `tibble` containing the node data. ### Example ```R create_notable('bull') %>% activate(nodes) %>% mutate(centrality = centrality_power()) %>% activate(edges) %>% mutate(mean_centrality = (.N()$centrality[from] + .N()$centrality[to])/2) ``` ``` -------------------------------- ### .E() Source: https://tidygraph.data-imaginist.com/reference/context_accessors.html Get the edges data from the graph you're currently working on. ```APIDOC ## .E(focused = TRUE) ### Description Get the edges data from the graph you're currently working on. ### Arguments * `focused` (logical) - Should only the attributes of the currently focused edges be returned. Defaults to TRUE. ### Value A `tibble` containing the edge data. ### Example ```R create_notable('bull') %>% activate(nodes) %>% mutate(centrality = centrality_power()) %>% activate(edges) %>% mutate(mean_centrality = (.N()$centrality[from] + .N()$centrality[to])/2) ``` ``` -------------------------------- ### Create and manipulate a contracted graph representation Source: https://tidygraph.data-imaginist.com/reference/morph.html This example demonstrates how to use `morph` to create a contracted graph representation based on node groups, compute centrality within this representation, and then `unmorph` to return to the original graph structure with the new centrality data. ```r create_notable('meredith') %>/ mutate(group = group_infomap()) %>/ morph(to_contracted, group) %>/ mutate(group_centrality = centrality_pagerank()) %>/ unmorph() #> # A tbl_graph: 70 nodes and 140 edges #> # #> # An undirected simple graph with 1 component #> # #> # Node Data: 70 × 2 (active) #> group group_centrality #> #> 1 1 0.1 #> 2 1 0.1 #> 3 1 0.1 #> 4 1 0.1 #> 5 1 0.1 #> 6 1 0.1 #> 7 1 0.1 #> 8 2 0.1 #> 9 2 0.1 #> 10 2 0.1 #> # ℹ 60 more rows #> # #> # Edge Data: 140 × 2 #> from to #> #> 1 1 5 #> 2 1 6 #> 3 1 7 #> # ℹ 137 more rows ``` -------------------------------- ### Example of mutate_as_tbl limitation Source: https://tidygraph.data-imaginist.com/reference/mutate_as_tbl.html Demonstrates a scenario where mutate_as_tbl cannot be used due to its limitation of updating the graph only at the end. The 'weights' variable is not available for the centrality_degree function within the same mutate call. ```r gr %>% activate(nodes) %>% mutate(weights = runif(10), degree = centrality_degree(weights)) ``` -------------------------------- ### Perform a random walk returning node order Source: https://tidygraph.data-imaginist.com/reference/random_walk_rank.html This snippet demonstrates how to use random_walk_rank to get the encounter order of nodes in a graph. It initializes a graph and then applies the function to mutate the node data with the walk ranks. ```R graph <- create_notable("zachary") # Random walk returning node order graph | mutate(walk_rank = random_walk_rank(200)) ``` -------------------------------- ### Get Node Depth using BFS Source: https://tidygraph.data-imaginist.com/reference/search_graph.html Demonstrates how to use `bfs_dist` to calculate the depth of each node from a specified root in a tree structure. The results are added as a new column 'depth' to the graph's node data. ```R # Get the depth of each node in a tree create_tree(10, 2) %>% activate(nodes) %>% mutate(depth = bfs_dist(root = 1)) ``` -------------------------------- ### Reorder Nodes using DFS Rank Source: https://tidygraph.data-imaginist.com/reference/search_graph.html Illustrates using `dfs_rank` to determine the order of nodes visited during a Depth-First Search starting from a specific node. The graph's nodes are then reordered based on this calculated order. ```R # Reorder nodes based on a depth first search from node 3 create_notable('franklin') %>% activate(nodes) %>% mutate(order = dfs_rank(root = 3)) %>% arrange(order) ``` -------------------------------- ### Get Immediate Dominator of Each Node Source: https://tidygraph.data-imaginist.com/reference/node_topology.html Calculates the immediate dominator for each node in a graph, starting from a specified root. Useful for analyzing control flow or hierarchical structures. Wraps `igraph::dominator_tree()`. ```R node_dominator(root, mode = "out") ``` -------------------------------- ### Create Notable Graph and Group Nodes with Infomap Source: https://tidygraph.data-imaginist.com/reference/group_graph.html This snippet shows how to create a graph from the 'tutte' dataset, activate the nodes, and then assign groups using the Infomap algorithm. ```r create_notable('tutte') %>% activate(nodes) %>% mutate(group = group_infomap()) #> # A tbl_graph: 46 nodes and 69 edges #> # #> # An undirected simple graph with 1 component #> # #> # Node Data: 46 × 1 (active) #> group #> #> 1 4 #> 2 1 #> 3 1 #> 4 1 #> 5 3 #> 6 3 #> 7 3 #> 8 2 #> 9 2 #> 10 2 #> # ℹ 36 more rows #> # #> # Edge Data: 69 × 2 #> from to #> #> 1 1 11 #> 2 1 12 #> 3 1 13 #> # ℹ 66 more rows ``` -------------------------------- ### Get Graph Order Source: https://tidygraph.data-imaginist.com/reference/graph_measures.html Returns the number of vertices in the graph. This function is part of the tidygraph framework. ```R graph_order() ``` -------------------------------- ### Get Graph Size Source: https://tidygraph.data-imaginist.com/reference/graph_measures.html Returns the number of edges in the graph. This function is part of the tidygraph framework. ```R graph_size() ``` -------------------------------- ### Activate Nodes and Edges using Special Pipes Source: https://tidygraph.data-imaginist.com/reference/activate.html Shows an alternative method to activate nodes and edges using the %N>% and %E>% pipes. This syntax can be more concise for simple operations but may reduce code readability compared to the activate function. ```r gr <- create_complete(5) %N>% mutate(class = sample(c('a', 'b'), 5, TRUE)) %E>% arrange(from) ``` -------------------------------- ### dfs_rank Source: https://tidygraph.data-imaginist.com/reference/search_graph.html Performs a Depth-First Search starting from a specified root node and returns the order in which nodes were visited. ```APIDOC ## dfs_rank ### Description Get the succession in which the nodes are visited in a depth first search. ### Arguments * `root`: The node to start the search from. * `mode`: How edges are followed. Options are "out", "in", "all", or "total". Ignored for undirected graphs. * `unreachable`: Logical. If TRUE, the search jumps to a new component if terminated early. Defaults to FALSE. ### Value An integer vector representing the order of node visitation. ``` -------------------------------- ### create_complete Source: https://tidygraph.data-imaginist.com/reference/create_graphs.html Creates a complete graph where every node is connected to every other node. Takes the number of nodes as an argument. ```APIDOC ## create_complete ### Description Create a complete graph (a graph where all nodes are connected). ### Arguments * **n** (integer) - The number of nodes in the graph. ### Value A tbl_graph object. ### Examples ```R # Create a complete graph with 10 nodes create_complete(10) ``` ``` -------------------------------- ### bfs_rank Source: https://tidygraph.data-imaginist.com/reference/search_graph.html Performs a Breadth-First Search starting from a specified root node and returns the order in which nodes were visited. ```APIDOC ## bfs_rank ### Description Get the succession in which the nodes are visited in a breath first search. ### Arguments * `root`: The node to start the search from. * `mode`: How edges are followed. Options are "out", "in", "all", or "total". Ignored for undirected graphs. * `unreachable`: Logical. If TRUE, the search jumps to a new component if terminated early. Defaults to FALSE. ### Value An integer vector representing the order of node visitation. ``` -------------------------------- ### Edge Rank Eulerian Function Signature Source: https://tidygraph.data-imaginist.com/reference/edge_rank.html This shows the function signature for `edge_rank_eulerian`. The `cyclic` argument determines if the Eulerian path should start and end at the same node. ```R edge_rank_eulerian(cyclic = FALSE) ``` -------------------------------- ### Create a Complete Graph Source: https://tidygraph.data-imaginist.com/reference/create_graphs.html Generates a complete graph where every node is connected to every other node. Use this for scenarios requiring maximum connectivity. ```R create_complete(10) #> # A tbl_graph: 10 nodes and 45 edges #> # #> # An undirected simple graph with 1 component #> # #> # Node Data: 10 × 0 (active) #> # #> # Edge Data: 45 × 2 #> from to #> #> 1 1 2 #> 2 1 3 #> 3 1 4 #> # ℹ 42 more rows ``` -------------------------------- ### create_path Source: https://tidygraph.data-imaginist.com/reference/create_graphs.html Creates a simple path graph with a specified number of nodes. Optionally, the graph can be directed and have mutual edges. ```APIDOC ## create_path ### Description Create a simple path. ### Arguments * **n** (integer) - The number of nodes in the graph. * **directed** (boolean) - Defaults to FALSE. Should the graph be directed? * **mutual** (boolean) - Defaults to FALSE. Should mutual edges be created in case of the graph being directed? ### Value A tbl_graph object. ``` -------------------------------- ### play_growing Source: https://tidygraph.data-imaginist.com/reference/evolution_games.html Creates graphs by adding a fixed number of edges at each iteration. This function models a simple growth process for graph evolution. ```APIDOC ## play_growing ### Description Create graphs by adding a fixed number of edges at each iteration. See `igraph::sample_growing()` ### Arguments * **n** (integer) - The number of nodes in the graph. * **growth** (numeric) - The number of edges added at each iteration. Defaults to 1. * **directed** (boolean) - Should the resulting graph be directed. Defaults to TRUE. * **citation** (boolean) - Should a citation graph be created. Defaults to FALSE. ### Value A tbl_graph object ``` -------------------------------- ### Activate Nodes and Edges in Tidygraph Source: https://tidygraph.data-imaginist.com/reference/activate.html Demonstrates how to use the activate function to switch between manipulating nodes and edges in a tbl_graph. This is useful for applying different transformations to different parts of the graph sequentially. ```r gr <- create_complete(5) %>% activate(nodes) %>% mutate(class = sample(c('a', 'b'), 5, TRUE)) %>% activate(edges) %>% arrange(from) ``` -------------------------------- ### create_bipartite Source: https://tidygraph.data-imaginist.com/reference/create_graphs.html Creates a full bipartite graph with specified numbers of nodes in each partition. The graph can be directed or undirected. ```APIDOC ## create_bipartite ### Description Create a full bipartite graph. ### Arguments * **n1** (integer) - The number of nodes in the first partition. * **n2** (integer) - The number of nodes in the second partition. * **directed** (boolean) - Defaults to FALSE. Should the graph be directed? * **mode** (character) - Defaults to "out". In case of a directed, non-mutual graph, should the edges flow 'out' or 'in'? ### Value A tbl_graph object. ``` -------------------------------- ### create_notable Source: https://tidygraph.data-imaginist.com/reference/create_graphs.html Creates a graph based on its name. A list of notable graph names can be found in `igraph::make_graph()`. ```APIDOC ## create_notable ### Description Create a graph based on its name. See `igraph::make_graph()`. ### Arguments * **name** (character) - The name of a notable graph. ### Value A tbl_graph object. ``` -------------------------------- ### Get Topological Order of Nodes in a DAG Source: https://tidygraph.data-imaginist.com/reference/node_topology.html Computes the topological order of nodes in a Directed Acyclic Graph (DAG). This is useful for processing nodes in an order that respects dependencies. Wraps `igraph::topo_sort()`. ```R node_topo_order(mode = "out") ``` -------------------------------- ### Basic Usage of `with_graph` Source: https://tidygraph.data-imaginist.com/reference/with_graph.html Demonstrates how to use `with_graph` to evaluate a centrality algorithm on a graph object outside of a tidygraph verb. Ensure the graph object is created and available before calling `with_graph`. ```R gr <- play_gnp(10, 0.3) with_graph(gr, centrality_degree()) #> [1] 4 4 2 3 2 6 4 3 3 2 ``` -------------------------------- ### Plotting a Forest Fire Graph Source: https://tidygraph.data-imaginist.com/reference/evolution_games.html Demonstrates how to plot a graph generated by the `play_forestfire` function. This is a basic visualization of the network structure created by the forest fire model. ```r plot(play_forestfire(50, 0.5)) ``` -------------------------------- ### play_preference Source: https://tidygraph.data-imaginist.com/reference/type_games.html Creates graphs by linking nodes of different types based on a defined probability. This function is analogous to `igraph::sample_pref()`. ```APIDOC ## play_preference ### Description Creates graphs by linking nodes of different types based on a defined probability. ### Method `play_preference(n, n_types, p_type, p_pref, fixed, directed, loops)` ### Parameters #### Path Parameters - **n** (numeric) - The number of nodes in the graph. - **n_types** (numeric) - The number of different node types in the graph. - **p_type** (numeric vector or matrix) - The probability that a node will be the given type. - **p_pref** (matrix) - The probability that an edge will be made to a type. - **fixed** (logical) - Should n_types be understood as a fixed number of nodes for each type rather than as a probability. - **directed** (logical) - Should the resulting graph be directed. - **loops** (logical) - Are loop edges allowed. ### Value A tbl_graph object ``` -------------------------------- ### play_fitness_power Source: https://tidygraph.data-imaginist.com/reference/sampling_games.html Creates graphs with an expected power-law degree distribution. This function is a wrapper around `igraph::sample_fitness_pl()`. ```APIDOC ## play_fitness_power ### Description Create graphs with an expected power-law degree distribution. ### Arguments * `n` (integer) - The number of nodes in the graph. * `m` (integer) - The number of edges in the graph. * `out_exp` (numeric) - Power law exponent of the out-degree distribution. * `in_exp` (numeric, optional) - Power law exponent of the in-degree distribution. Defaults to `-1`. * `loops` (boolean, optional) - Are loop edges allowed. Defaults to `FALSE`. * `multiple` (boolean, optional) - Are multiple edges allowed. Defaults to `FALSE`. * `correct` (boolean, optional) - Use finite size correction. Defaults to `TRUE`. ### Value A tbl_graph object. ### See Also `igraph::sample_fitness_pl()` ``` -------------------------------- ### Perform a random walk returning edge order Source: https://tidygraph.data-imaginist.com/reference/random_walk_rank.html This snippet shows how to use random_walk_rank to get the encounter order of edges in a graph. It activates the edges of the graph before applying the function to mutate the edge data with the walk ranks. ```R graph | activate(edges) | mutate(walk_rank = random_walk_rank(200)) ``` -------------------------------- ### create_tree Source: https://tidygraph.data-imaginist.com/reference/create_graphs.html Creates a tree graph with a specified number of nodes and children per node. The graph is directed by default. ```APIDOC ## create_tree ### Description Create a tree graph. ### Arguments * **n** (integer) - The number of nodes in the graph. * **children** (integer) - The number of children each node has (if possible). * **directed** (boolean) - Defaults to TRUE. Should the graph be directed? * **mode** (character) - Defaults to "out". In case of a directed, non-mutual graph, should the edges flow 'out' or 'in'? ### Value A tbl_graph object. ``` -------------------------------- ### reroute(.data, from = NULL, to = NULL, subset = NULL) Source: https://tidygraph.data-imaginist.com/reference/reroute.html Changes the beginning and end node of edges by specifying the new indexes of the start and/or end node(s). Optionally, only a subset of edges can be rerouted using the subset argument. ```APIDOC ## reroute ### Description Changes the beginning and end node of edges by specifying the new indexes of the start and/or end node(s). Optionally, only a subset of edges can be rerouted using the subset argument. ### Arguments * **.data** (tbl_graph or morphed_tbl_graph) - A tbl_graph or morphed_tbl_graph object. grouped_tbl_graph will be ungrouped prior to rerouting. * **from, to** (numeric or NULL) - The new indexes of the terminal nodes. If `NULL` nothing will be changed. * **subset** (expression) - An expression evaluating to an indexing vector in the context of the edge data. If `NULL` it will use focused edges if available or all edges. ### Value An object of the same class as .data ### Examples ```R # Switch direction of edges create_notable('meredith') %>% activate(edges) %>% reroute(from = to, to = from) # Using subset create_notable('meredith') %>% activate(edges) %>% reroute(from = 1, subset = to > 10) ``` ``` -------------------------------- ### play_gnm Source: https://tidygraph.data-imaginist.com/reference/sampling_games.html Creates graphs with a fixed number of edges. This function is a wrapper around `igraph::sample_gnm()`. ```APIDOC ## play_gnm ### Description Create graphs with a fixed edge count. ### Arguments * `n` (integer) - The number of nodes in the graph. * `m` (integer) - The number of edges in the graph. * `directed` (boolean, optional) - Should the resulting graph be directed. Defaults to `TRUE`. * `loops` (boolean, optional) - Are loop edges allowed. Defaults to `FALSE`. ### Value A tbl_graph object. ### See Also `igraph::sample_gnm()` ``` -------------------------------- ### play_geometry Source: https://tidygraph.data-imaginist.com/reference/sampling_games.html Creates graphs by positioning nodes on a plane or torus and connecting nearby ones. This function is a wrapper around `igraph::sample_grg()`. ```APIDOC ## play_geometry ### Description Create graphs by positioning nodes on a plane or torus and connecting nearby ones. ### Arguments * `n` (integer) - The number of nodes in the graph. * `radius` (numeric) - The radius within which vertices are connected. * `torus` (boolean, optional) - Should the vertices be distributed on a torus instead of a plane. Defaults to `FALSE`. ### Value A tbl_graph object. ### See Also `igraph::sample_grg()` ``` -------------------------------- ### create_ring Source: https://tidygraph.data-imaginist.com/reference/create_graphs.html Creates a simple ring graph with a specified number of nodes. Optionally, the graph can be directed and have mutual edges. ```APIDOC ## create_ring ### Description Create a simple ring graph. ### Arguments * **n** (integer) - The number of nodes in the graph. * **directed** (boolean) - Defaults to FALSE. Should the graph be directed? * **mutual** (boolean) - Defaults to FALSE. Should mutual edges be created in case of the graph being directed? ### Value A tbl_graph object. ``` -------------------------------- ### create_lattice Source: https://tidygraph.data-imaginist.com/reference/create_graphs.html Creates a multidimensional grid of nodes. The graph can be directed or undirected, and dimensions can optionally wrap around. ```APIDOC ## create_lattice ### Description Create a multidimensional grid of nodes. ### Arguments * **dim** (integer vector) - The dimensions of the lattice. * **directed** (boolean) - Defaults to FALSE. Should the graph be directed? * **mutual** (boolean) - Defaults to FALSE. Should mutual edges be created in case of the graph being directed? * **circular** (boolean) - Defaults to FALSE. Should each dimension in the lattice wrap around? ### Value A tbl_graph object. ``` -------------------------------- ### random_walk_rank Source: https://tidygraph.data-imaginist.com/reference/random_walk_rank.html Performs a random walk on the graph to determine the encounter rank of nodes or edges. The walk starts from a specified root node or a random node and proceeds for a given number of steps, following edges based on the specified mode (out, in, all). The function returns a list where each element represents the encounter order of nodes or edges. ```APIDOC ## random_walk_rank ### Description Performs a random walk on the graph and returns the encounter rank of nodes or edges. The walk can be initiated from a specific node or a random node and can traverse edges in different modes (out, in, all). ### Arguments * **n** (integer) - The number of steps to perform in the random walk. If the walk gets stuck before reaching this number, it terminates early. * **root** (node, optional) - The node from which to start the random walk. If `NULL`, a random node is chosen as the starting point. * **mode** (character, optional) - Specifies how edges are followed in directed graphs. Options are: * `"out"`: Follows only outbound edges. * `"in"`: Follows only inbound edges. * `"all"` or `"total"`: Follows all edges. This argument is ignored for undirected graphs. * **weights** (numeric vector, optional) - The weights to use for selecting the next step of the walk. Currently, this is only used when edges are active. ### Value A list containing an integer vector for each node or edge (depending on what is active). Each element in the vector encodes the time (step number) the node/edge was encountered along the walk. ### Examples __``` graph <- create_notable("zachary") # Random walk returning node order graph |> mutate(walk_rank = random_walk_rank(200)) #> # A tbl_graph: 34 nodes and 78 edges #> # #> # An undirected simple graph with 1 component #> # #> # Node Data: 34 × 1 (active) #> walk_rank #> #> 1 #> 2 #> 3 #> 4 #> 5 #> 6 #> 7 #> 8 #> 9 #> 10 #> # ℹ 24 more rows #> # #> # Edge Data: 78 × 2 #> from to #> #> 1 1 2 #> 2 1 3 #> 3 1 4 #> # ℹ 75 more rows # Rank edges instead graph |> activate(edges) |> mutate(walk_rank = random_walk_rank(200)) #> # A tbl_graph: 34 nodes and 78 edges #> # #> # An undirected simple graph with 1 component #> # #> # Edge Data: 78 × 3 (active) #> from to walk_rank #> #> 1 1 2 #> 2 1 3 #> 3 1 4 #> 4 1 5 #> 5 1 6 #> 6 1 7 #> 7 1 8 #> 8 1 9 #> 9 1 11 #> 10 1 12 #> # ℹ 68 more rows #> # #> # Node Data: 34 × 0 ``` -------------------------------- ### create_chordal_ring Source: https://tidygraph.data-imaginist.com/reference/create_graphs.html Creates a chordal ring graph with a specified number of nodes and additional edges defined by a matrix. ```APIDOC ## create_chordal_ring ### Description Create a chordal ring. ### Arguments * **n** (integer) - The number of nodes in the graph. * **w** (matrix) - A matrix specifying the additional edges in the chordal ring. See `igraph::make_chordal_ring()`. ### Value A tbl_graph object. ``` -------------------------------- ### Node Ranking Functions Overview Source: https://tidygraph.data-imaginist.com/reference/node_rank.html Provides a list of available node ranking functions. These functions are valuable for ordering nodes in a graph based on topological proximity, aiding in visualization and layout composition. ```R node_rank_hclust( method = "average", dist = "shortest", mode = "out", weights = NULL, algorithm = "automatic" ) node_rank_anneal( cool = 0.5, tmin = 1e-04, swap_to_inversion = 0.5, step_multiplier = 100, reps = 1, dist = "shortest", mode = "out", weights = NULL, algorithm = "automatic" ) node_rank_branch_bound( weighted_gradient = FALSE, dist = "shortest", mode = "out", weights = NULL, algorithm = "automatic" ) node_rank_traveller( method = "two_opt", ..., dist = "shortest", mode = "out", weights = NULL, algorithm = "automatic" ) node_rank_two( dist = "shortest", mode = "out", weights = NULL, algorithm = "automatic" ) node_rank_mds( method = "cmdscale", dist = "shortest", mode = "out", weights = NULL, algorithm = "automatic" ) node_rank_leafsort( method = "average", type = "OLO", dist = "shortest", mode = "out", weights = NULL, algorithm = "automatic" ) node_rank_visual( dist = "shortest", mode = "out", weights = NULL, algorithm = "automatic" ) node_rank_spectral( normalized = FALSE, dist = "shortest", mode = "out", weights = NULL, algorithm = "automatic" ) node_rank_spin_out( step = 25, nstart = 10, dist = "shortest", mode = "out", weights = NULL, algorithm = "automatic" ) node_rank_spin_in( step = 5, sigma = seq(20, 1, length.out = 10), dist = "shortest", mode = "out", weights = NULL, algorithm = "automatic" ) node_rank_quadratic( criterion = "2SUM", reps = 1, step = 2 * graph_order(), step_multiplier = 1.1, temp_multiplier = 0.5, maxsteps = 50, dist = "shortest", mode = "out", weights = NULL, algorithm = "automatic" ) node_rank_genetic( ..., dist = "shortest", mode = "out", weights = NULL, algorithm = "automatic" ) node_rank_dendser( ..., dist = "shortest", mode = "out", weights = NULL, algorithm = "automatic" ) ``` -------------------------------- ### play_preference_asym Source: https://tidygraph.data-imaginist.com/reference/type_games.html Creates graphs by linking nodes of different types based on an asymmetric probability. This function is analogous to `igraph::sample_asym_pref()`. ```APIDOC ## play_preference_asym ### Description Creates graphs by linking nodes of different types based on an asymmetric probability. ### Method `play_preference_asym(n, n_types, p_type, p_pref, loops)` ### Parameters #### Path Parameters - **n** (numeric) - The number of nodes in the graph. - **n_types** (numeric) - The number of different node types in the graph. - **p_type** (matrix) - The probability that a node will be the given type. - **p_pref** (matrix) - The probability that an edge will be made to a type. - **loops** (logical) - Are loop edges allowed. ### Value A tbl_graph object ``` -------------------------------- ### play_bipartite Source: https://tidygraph.data-imaginist.com/reference/type_games.html Creates bipartite graphs of fixed size and edge count or probability. This function is analogous to `igraph::sample_bipartite()`. ```APIDOC ## play_bipartite ### Description Creates bipartite graphs of fixed size and edge count or probability. ### Method `play_bipartite(n1, n2, p, m, directed, mode)` ### Parameters #### Path Parameters - **n1** (numeric) - The number of nodes of the first type in the bipartite graph. - **n2** (numeric) - The number of nodes of the second type in the bipartite graph. - **p** (numeric) - The probability of an edge occurring. - **m** (numeric) - The number of edges in the graph. - **directed** (logical) - Should the resulting graph be directed. - **mode** (character) - The flow direction of edges. ### Value A tbl_graph object ### Examples ``` plot(play_bipartite(20, 30, 0.4)) ``` ``` -------------------------------- ### play_fitness Source: https://tidygraph.data-imaginist.com/reference/sampling_games.html Creates graphs where edge probabilities are proportional to terminal node fitness scores. This function is a wrapper around `igraph::sample_fitness()`. ```APIDOC ## play_fitness ### Description Create graphs where edge probabilities are proportional to terminal node fitness scores. ### Arguments * `m` (integer) - The number of edges in the graph. * `out_fit` (numeric vector) - The fitness of each node for outgoing edges. * `in_fit` (numeric vector, optional) - The fitness of each node for incoming edges. * `loops` (boolean, optional) - Are loop edges allowed. Defaults to `FALSE`. * `multiple` (boolean, optional) - Are multiple edges allowed. Defaults to `FALSE`. ### Value A tbl_graph object. ### See Also `igraph::sample_fitness()` ``` -------------------------------- ### play_gnp Source: https://tidygraph.data-imaginist.com/reference/sampling_games.html Creates graphs with a fixed probability of edge occurrence. This function is a wrapper around `igraph::sample_gnp()`. ```APIDOC ## play_gnp ### Description Create graphs with a fixed edge probability. ### Arguments * `n` (integer) - The number of nodes in the graph. * `p` (numeric) - The probability of an edge occurring between any two nodes. * `directed` (boolean, optional) - Should the resulting graph be directed. Defaults to `TRUE`. * `loops` (boolean, optional) - Are loop edges allowed. Defaults to `FALSE`. ### Value A tbl_graph object. ### See Also `igraph::sample_gnp()` ``` -------------------------------- ### Growing Graph Creation Source: https://tidygraph.data-imaginist.com/reference/evolution_games.html Creates graphs by iteratively adding a fixed number of edges. This function is suitable for modeling network growth over time where a constant rate of new connections is maintained. ```r play_growing(n, growth = 1, directed = TRUE, citation = FALSE) ``` -------------------------------- ### create_star Source: https://tidygraph.data-imaginist.com/reference/create_graphs.html Creates a star graph, where a central node is connected to all other nodes. The graph can be directed or undirected. ```APIDOC ## create_star ### Description Create a star graph (a single node in the center connected to all other nodes). ### Arguments * **n** (integer) - The number of nodes in the graph. * **directed** (boolean) - Defaults to FALSE. Should the graph be directed? * **mutual** (boolean) - Defaults to FALSE. Should mutual edges be created in case of the graph being directed? * **mode** (character) - Defaults to "out". In case of a directed, non-mutual graph, should the edges flow 'out' or 'in'? ### Value A tbl_graph object. ``` -------------------------------- ### Group by Louvain Algorithm Source: https://tidygraph.data-imaginist.com/reference/group_graph.html Groups nodes by multilevel optimization of modularity using igraph::cluster_louvain(). This algorithm is known for its speed and ability to find good community structures. ```R group_louvain(weights = NULL, resolution = 1) ``` -------------------------------- ### morph, unmorph, crystallise, crystallize, convert Source: https://tidygraph.data-imaginist.com/reference/morph.html Functions for creating, manipulating, and extracting temporary graph representations. ```APIDOC ## morph, unmorph, crystallise, crystallize, convert ### Description Functions for creating, manipulating, and extracting temporary graph representations. ### Functions - `morph(.data, .f, ...)`: Creates a temporary alternative representation of the graph. - `unmorph(.data)`: Reverts the graph to its original state after morphing. - `crystallise(.data)`: Extracts temporary graph representations into a tibble. - `crystallize(.data)`: Alias for `crystallise`. - `convert(.data, .f, ..., .select = 1, .clean = FALSE)`: A shorthand for performing `morph` and `crystallise`, extracting a single `tbl_graph`. ### Arguments - `.data`: A `tbl_graph` or a `morphed_tbl_graph`. - `.f`: A morphing function. See morphers for a list of provided ones. - `...`: Arguments passed on to the morpher. - `.select`: The graph to return during `convert()`. Either an index or the name as created during `crystallise()`. - `.clean`: Should references to the node and edge indexes in the original graph be removed when using `convert`. ### Value A `morphed_tbl_graph`. ### Details - It is only possible to change and add to node and edge data from a morphed state. Any filtering/removal of nodes and edges will not result in removal from the main graph. - Morphing an already morphed graph will unmorph prior to applying the new morph. - During a morphed state, the mapping back to the original graph is stored in `.tidygraph_node_index` and `.tidygraph_edge_index` columns. - Custom morphers should accept a `tbl_graph` as their first input and return a `tbl_graph` or a list of `tbl_graph`s containing `.tidygraph_node_index` or `.tidygraph_edge_index` columns. ### Examples ```R create_notable('meredith') %>% mutate(group = group_infomap()) %>% morph(to_contracted, group) %>% mutate(group_centrality = centrality_pagerank()) %>% unmorph() ``` ``` -------------------------------- ### Graph Generation Functions Source: https://tidygraph.data-imaginist.com/reference/sampling_games.html Lists the available graph generation functions in `tidygraph` that use direct sampling methods. ```R play_degree(out_degree, in_degree = NULL, method = "simple") play_dotprod(position, directed = TRUE) play_fitness(m, out_fit, in_fit = NULL, loops = FALSE, multiple = FALSE) play_fitness_power( n, m, out_exp, in_exp = -1, loops = FALSE, multiple = FALSE, correct = TRUE ) play_gnm(n, m, directed = TRUE, loops = FALSE) play_gnp(n, p, directed = TRUE, loops = FALSE) play_geometry(n, radius, torus = FALSE) play_erdos_renyi(n, p, m, directed = TRUE, loops = FALSE) ```