Description Usage Arguments Value Examples
View source: R/num_qual_neighbors.R
Using the 'tidygraph' functions map_local_*()
, it is easy to scan the
neighborhood of all the nodes in a graph. This function takes a logical
filter expression to apply on the node attributes of a graph, and returns the
number of neighbors that qualify.
1 | num_qual_neighbors(neighborhood, lgl_filter, ignore_nodes = c(), ...)
|
neighborhood |
passed by the |
lgl_filter |
an expression to apply to the node attributes of
|
ignore_nodes |
nodes to exclude from the filter (use the |
... |
just takes any other arguments passed automatically by
|
an integer of the number of nodes that qualify for each neighborhood
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | suppressPackageStartupMessages(library(tidygraph))
set.seed(0)
gr <- quick_barabasi(30)
gr
plot(gr)
# number of neighbors with a "B" in their name
B_gr <- gr %>%
mutate(name_with_B = map_local_int(
.f = num_qual_neighbors,
lgl_filter = rlang::expr(stringr::str_detect(name, "B"))
))
B_gr %N>%
filter(name_with_B > 0) %>%
plot()
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.