I'm having some trouble groking certain Tidygraph operations that are relatively straightforward in igraph.
In particular I would like to analyze specific neighborhoods at different orders. I think I need to use Morphs for this, but I just haven't got it working.
library(tidygraph)
library(ggraph)
net <- tibble::tibble(A = letters[1:6],
B = rep(c("x", "y"), each = 3)) %>%
tidygraph::as_tbl_graph()
For example, say I have the following network structure:
I want to analyze the neighborhood about x.
net %>%
ggraph(layout = "nicely") +
geom_edge_link() +
geom_node_point(size = 10, fill = "white", shape = 21) +
geom_node_text(aes(label = name)) +
theme_graph()
The iGraph implementation works as follows:
Extract the neighborhood of node x.
v <- net %>%
tidygraph::as.igraph() %>%
igraph::neighborhood(nodes = "x", order = 1)
build a subgraph by unlisting the igraph.vs object
igraph::induced_subgraph(net, vids = unlist(v)) %>%
tidygraph::as_tbl_graph() %>%
ggraph(layout = "nicely") +
geom_edge_link() +
geom_node_point(size = 10, fill = "white", shape = 21) +
geom_node_text(aes(label = name)) +
theme_graph()
How do I do this with tidygraph?
The following implementations return the same error:
net %>%
tidygraph::morph(to_local_neighborhood, node = "x", order = 1, mode = "all")
net %>%
to_local_neighborhood(node = "x", order = 1, mode = "all")
Error in if (is.numeric(v) && any(v < 0)) { : missing value where TRUE/FALSE needed