select_nodes_in_neighborhood {DiagrammeR} | R Documentation

## Select nodes based on a walk distance from a specified node

### Description

Select those nodes in the neighborhood of nodes connected a specified distance from an initial node.

### Usage

    select_nodes_in_neighborhood(graph, node, distance, set_op = "union")

### Arguments

`graph` | a graph object of class `dgr_graph` that is created using `create_graph`.
`node` | the node from which the traversal will originate.
`distance` | the maximum number of steps from the `node` for inclusion in the subgraph.
`set_op` | the set operation to perform upon consecutive selections of graph nodes. This can either be as a `union` (the default), as an `intersection`, or, as a `difference` on the previous selection, if it exists.

### Value

a graph object of class `dgr_graph`.

### Examples

    ## Not run:
    # Create a graph, then, create a subgraph of that larger graph
    nodes <-
      create_nodes(nodes = LETTERS,
                   type = "letter",
                   shape = sample(c("circle", "rectangle"),
                                  length(LETTERS),
                                  replace = TRUE),
                   fillcolor = sample(c("aqua", "red",
                                        "pink", "lightgreen",
                                        "azure", "yellow"),
                                      length(LETTERS),
                                      replace = TRUE))

    edges <-
      create_edges(from = sample(LETTERS, replace = TRUE),
                   to = sample(LETTERS, replace = TRUE),
                   rel = "letter_to_letter")

    graph <- create_graph(nodes_df = nodes,
                          edges_df = edges,
                          graph_attrs = "layout = neato",
                          node_attrs = c("fontname = Helvetica",
                                         "style = filled"),
                          edge_attrs = c("color = gray20",
                                         "arrowsize = 0.5"))

    # Create a selection of nodes centered around node "U" and
    # including those nodes a depth of 2 edges away
    graph <-
      select_nodes_in_neighborhood(graph = graph,
                                   node = "U",
                                   distance = 2)

    ## End(Not run)

[Package DiagrammeR version 0.8.2 Index]