create_edge_df: Create an edge data frame

Description Usage Arguments Value Examples

View source: R/create_edge_df.R

Description

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

- id (of type integer)

- from (of type integer)

- to (of type integer)

- rel (of type character)

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

Usage

1
create_edge_df(from, to, rel = NULL, ...)

Arguments

from

a vector of node ID values from which edges are outbound. The vector length must equal that of the to vector.

to

a vector of node ID values to which edges are incoming. The vector length must equal that of the from vector.

rel

an optional rel label for each edge.

...

one or more vectors for associated edge attributes.

Value

an edge data frame (edf).

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
# Create a simple edge data frame (edf) and
# view the results
edf <-
  create_edge_df(
    from = c(1, 2, 3),
    to = c(4, 3, 1),
    rel = "a")

# Display the edge data frame
edf

# Create an edf with additional edge
# attributes (where their classes will
# be inferred from the input vectors)
edf <-
  create_edge_df(
    from = c(1, 2, 3),
    to = c(4, 3, 1),
    rel = "a",
    length = c(50, 100, 250),
    color = "green",
    width = c(1, 5, 2))

# Display the edge data frame
edf

Example output

  id from to rel
1  1    1  4   a
2  2    2  3   a
3  3    3  1   a
  id from to rel length color width
1  1    1  4   a     50 green     1
2  2    2  3   a    100 green     5
3  3    3  1   a    250 green     2

DiagrammeR documentation built on March 18, 2018, 1:25 p.m.