select_nodes_by_degree {DiagrammeR} | R Documentation |
Using a graph object of class
dgr_graph
, create a selection of nodes
that have certain degree values.
select_nodes_by_degree(graph, expressions, set_op = "union")
graph |
a graph object of class
|
expressions |
one or more expressions for
filtering of nodes by degree values. Use a
combination of a degree type ( |
set_op |
the set operation to perform upon
consecutive selections of graph nodes. This can
either be as a |
a graph object of class dgr_graph
.
# Create a random graph with a high amount # of connectedness graph <- create_random_graph( n = 35, m = 125, set_seed = 23) # Report which nodes have a total degree (indegree # + outdegree) of exactly 9 graph %>% select_nodes_by_degree("deg == 9") %>% get_selection() #> [1] 2 9 10 14 17 19 31 33 # Report which nodes have a total degree greater # than or equal to 9 graph %>% select_nodes_by_degree("deg >= 9") %>% get_selection() #> [1] 2 6 9 10 14 17 19 22 25 29 31 33 # Combine two calls of `select_nodes_by_degree()` # to get those nodes with total degree less than # 3 and total degree greater than 10 (by default, # those `select...()` functions `union` the sets # of nodes selected) graph %>% select_nodes_by_degree("deg < 3") %>% select_nodes_by_degree("deg > 10") %>% get_selection() #> [1] 6 16 22 # Combine two calls of `select_nodes_by_degree()` # to get those nodes with total degree greater than # or equal to 3 and less than or equal to 10 (the # key here is to `intersect` the sets of nodes # selected in the second call) graph %>% select_nodes_by_degree("deg >= 3") %>% select_nodes_by_degree("deg <= 10", "intersect") %>% get_selection() #> [1] 1 2 3 4 5 7 8 9 10 11 12 13 14 #> [14] 15 17 18 19 20 21 23 24 25 26 27 28 29 #> [28] 30 31 32 33 34 35 # Select all nodes with an indegree greater than 5, # then, apply a node attribute to those selected nodes # (coloring the selected nodes red) graph_2 <- graph %>% select_nodes_by_degree("indeg > 5") %>% set_node_attrs_ws("color", "red") # Get the selection of nodes graph_2 %>% get_selection() #> [1] 14 22 23 25 27 29 31 33 34