Consider this simple example
library(tidygraph)
mynodes <- tibble(id = c(1,2,3,4,5))
myedges <- tibble(from = c(1,1,1,5),
to = c(1,2,3,4),
power = c(10,10,10,3))
tbl_graph(nodes = mynodes, edges = myedges)
# A tbl_graph: 5 nodes and 4 edges
#
# A directed multigraph with 2 components
#
# Node Data: 5 x 1 (active)
id
<dbl>
1 1
2 2
3 3
4 4
5 5
#
# Edge Data: 4 x 3
from to power
<int> <int> <dbl>
1 1 1 10
2 1 2 10
3 1 3 10
# ? with 1 more row
I know I can use filter
to easily filter the nodes or the edges.
My problem is how to filter the nodes based on a condition on the edges.
For instance running:
mygraph %>% activate(edges) %>% filter(power == 3)
will still returns all the nodes, which is annoying when plotting (these nodes will have no edges!).
How can I keep all nodes that are connected with my filtered set of edges?
# A tbl_graph: 5 nodes and 1 edges
#
# A rooted forest with 4 trees
#
# Edge Data: 1 x 3 (active)
from to power
<int> <int> <dbl>
1 5 4 3
#
# Node Data: 5 x 1
id
<dbl>
1 1
2 2
3 3
# ? with 2 more rows