get_nbrs: Get all neighbors of one or more nodes

Description Usage Arguments Value Examples

View source: R/get_nbrs.R

Description

With one or more nodes, get the set of all neighboring nodes.

Usage

1
get_nbrs(graph, nodes)

Arguments

graph

a graph object of class dgr_graph.

nodes

a vector of node ID values.

Value

a vector of node ID values.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# Create a simple, directed graph with 5
# nodes and 4 edges
graph <-
  create_graph() %>%
  add_path(5)

# Find all neighbor nodes for node `2`
graph %>% get_nbrs(2)
#> [1] 1 3

# Find all neighbor nodes for nodes `1`
# and `5`
graph %>% get_nbrs(c(1, 5))
#> [1] 2 4

# Color node `3` with purple, get its
# neighbors and color those nodes green
graph <-
  graph %>%
  select_nodes_by_id(3) %>%
  set_node_attrs_ws("color", "purple") %>%
  clear_selection() %>%
  select_nodes_by_id(get_nbrs(., 3)) %>%
  set_node_attrs_ws("color", "green")

DiagrammeR documentation built on May 30, 2017, 1:15 a.m.

Search within the DiagrammeR package
Search all R packages, documentation and source code