create_node_df: Create a node data frame

Description Usage Arguments Details Value See Also Examples

View source: R/create_node_df.R

Description

Combine several vectors for nodes and their attributes into a data frame, which can be combined with other similarly-generated data frames, or, added to a graph object. A node data frame, or ndf, has at least the following columns:

Usage

1
create_node_df(n, type = NULL, label = NULL, ...)

Arguments

n

The total number of nodes to include in the node data frame.

type

An optional type for each node.

label

An optional label for each node.

...

One or more vectors for associated node attributes.

Details

An arbitrary number of additional columns containing aesthetic or data attributes can be part of the ndf, so long as they follow the aforementioned columns.

Value

A node data frame (ndf).

See Also

Other Node creation and removal: add_n_node_clones(), add_n_nodes_ws(), add_n_nodes(), add_node_clones_ws(), add_node_df(), add_nodes_from_df_cols(), add_nodes_from_table(), add_node(), colorize_node_attrs(), copy_node_attrs(), delete_nodes_ws(), delete_node(), drop_node_attrs(), join_node_attrs(), layout_nodes_w_string(), mutate_node_attrs_ws(), mutate_node_attrs(), node_data(), recode_node_attrs(), rename_node_attrs(), rescale_node_attrs(), set_node_attr_to_display(), set_node_attr_w_fcn(), set_node_attrs_ws(), set_node_attrs(), set_node_position()

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
25
26
27
28
29
30
# Create a node data frame (ndf) where the labels
# are equivalent to the node ID values (this is not
# recommended); the `label` and `type` node
# attributes will always be a `character` class
# whereas `id` will always be an `integer`
node_df <-
  create_node_df(
    n = 4,
    type = c("a", "a", "b", "b"),
    label = TRUE)

# Display the node data frame
node_df

# Create an ndf with distinct labels and
# additional node attributes (where their classes
# will be inferred from the input vectors)
node_df <-
  create_node_df(
    n = 4,
    type = "a",
    label = c(2384, 3942, 8362, 2194),
    style = "filled",
    color = "aqua",
    shape = c("circle", "circle",
              "rectangle", "rectangle"),
    value = c(3.5, 2.6, 9.4, 2.7))

# Display the node data frame
node_df

Example output

  id type label
1  1    a     1
2  2    a     2
3  3    b     3
4  4    b     4
  id type label  style color     shape value
1  1    a  2384 filled  aqua    circle   3.5
2  2    a  3942 filled  aqua    circle   2.6
3  3    a  8362 filled  aqua rectangle   9.4
4  4    a  2194 filled  aqua rectangle   2.7

DiagrammeR documentation built on July 2, 2020, 3:19 a.m.