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"
Run the code above in your browser using DataLab