add_grid_3d {DiagrammeR} | R Documentation

## Add a 3D grid of nodes to the graph

### Description

With a graph object of class `dgr_graph`, add a three-dimensional grid to the graph.

### Usage

    add_grid_3d(graph, x, y, z, type = NULL, label = TRUE, rel = NULL,
      node_aes = NULL, edge_aes = NULL, node_data = NULL, edge_data = NULL)

### Arguments

`graph` | a graph object of class `dgr_graph`.
`x` | the number of nodes in the x direction.
`y` | the number of nodes in the y direction.
`z` | the number of nodes in the z direction.
`type` | an optional string that describes the entity type for the nodes to be added.
`label` | either a vector object of length `x * y * z` that provides optional labels for the new nodes, or, a boolean value where setting to `TRUE` ascribes node IDs to the label and `FALSE` yields a blank label.
`rel` | an optional string for providing a relationship label to all new edges created in the grid.
`node_aes` | an optional list of named vectors comprising node aesthetic attributes. The helper function `node_aes()` is strongly recommended for use here as it contains arguments for each of the accepted node aesthetic attributes (e.g., `shape`, `style`, `color`, `fillcolor`).
`edge_aes` | an optional list of named vectors comprising edge aesthetic attributes. The helper function `edge_aes()` is strongly recommended for use here as it contains arguments for each of the accepted edge aesthetic attributes (e.g., `shape`, `style`, `penwidth`, `color`).
`node_data` | an optional list of named vectors comprising node data attributes. The helper function `node_data()` is strongly recommended for use here as it helps bind data specifically to the created nodes.
`edge_data` | an optional list of named vectors comprising edge data attributes. The helper function `edge_data()` is strongly recommended for use here as it helps bind data specifically to the created edges.

### Value

a graph object of class `dgr_graph`.

### Examples

    # Create a new graph and add
    # a 2 x 2 x 2 grid
    graph <-
      create_graph() %>%
      add_grid_3d(
        x = 2, y = 2, z = 2,
        type = "grid")

    # Get node information
    # from this graph
    graph %>%
      get_node_info()

    # Attributes can be specified
    # in extra arguments and these
    # are applied in order; Usually
    # these attributes are applied
    # to nodes (e.g., `type` is a
    # node attribute) but the `rel`
    # attribute will apply to the
    # edges
    graph_w_attrs <-
      create_graph() %>%
      add_grid_3d(
        x = 2, y = 2, z = 2,
        label = c(
          "one", "two", "three",
          "four", "five", "six",
          "seven", "eight"),
        type = c(
          "a", "a", "b",
          "b", "c", "c",
          "d", "d"),
        rel = "grid",
        node_data = node_data(
          value = c(
            1.2, 8.4, 3.4,
            5.2, 6.1, 2.6,
            6.3, 9.3)))

    # Get the graph's node data frame
    graph_w_attrs %>%
      get_node_df()

    # Get the graph's edge data frame
    graph_w_attrs %>%
      get_edge_df()

[Package DiagrammeR version 1.0.1 Index]