select_edges {DiagrammeR} | R Documentation |
Select edges from a graph object of
class dgr_graph
.
select_edges(graph, edge_attr = NULL, search = NULL, set_op = "union", from = NULL, to = NULL)
graph |
a graph object of class
|
edge_attr |
an optional character vector of edge attribute values for filtering the edges returned. |
search |
an option to provide a logical
expression with a comparison operator ( |
set_op |
the set operation to perform upon
consecutive selections of graph nodes. This can
either be as a |
from |
an optional vector of node IDs from which the edge is outgoing for filtering the list of edges present in the graph. |
to |
an optional vector of node IDs to which the edge is incoming for filtering the list of edges present in the graph. |
a graph object of class dgr_graph
.
library(magrittr) # Create a node data frame (ndf) nodes <- create_nodes( nodes = c("a", "b", "c", "d"), type = "letter", label = TRUE, value = c(3.5, 2.6, 9.4, 2.7)) # Create an edge data frame (edf) edges <- create_edges( from = c("a", "b", "c"), to = c("d", "c", "a"), rel = c("A", "Z", "A"), value = c(6.4, 2.9, 5.0)) # Create a graph with the ndf and edf graph <- create_graph(nodes_df = nodes, edges_df = edges) # Explicitly select the edge `a` -> `d` graph <- graph %>% select_edges( from = "a", to = "d") # Verify that an edge selection has been made # using the `get_selection()` function get_selection(graph) #> $edges #> $edges$from #> [1] "b" #> #> $edges$to #> [1] "c" # Select edges based on the relationship label # being `Z` graph <- graph %>% clear_selection %>% select_edges( edge_attr = "rel", search = "Z") # Verify that an edge selection has been made, and # recall that the `b` -> `c` edge uniquely has the # `Z` relationship label get_selection(graph) #> $edges #> $edges$from #> [1] "b" #> #> $edges$to #> [1] "c" # Select edges based on the edge value attribute # being greater than 3.0 (first clearing the current # selection of edges) graph <- graph %>% clear_selection %>% select_edges( edge_attr = "value", search = ">3.0") # Verify that the correct edge selection has been # made; in this case, edges `a` -> `d` and # `c` -> `a` have values for `value` greater than # 3.0 get_selection(graph) #> $edges #> $edges$from #> [1] "a" "c" #> #> $edges$to #> [1] "d" "a"