Learn R Programming

DiagrammeR (version 0.8.4)

create_edges: Create a data frame with edges and their attributes

Description

Combine several named 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.

Usage

create_edges(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 named vectors for associated attributes.

Value

an edge data frame (edf).

Examples

Run this code
# Create a simple edge data frame (edf) and
# view the results
edges <-
  create_edges(
    from = c(1, 2, 3),
    to = c(4, 3, 1),
    rel = "a")

# Display the `edges` edf
edges
#>   from to rel
#> 1    1  4   a
#> 2    2  3   a
#> 3    3  1   a

# Render the graph to make it viewable in
# the Viewer pane
render_graph(
  create_graph(edges_df = edges),
  output = "visNetwork")

# Create an edge data frame with several
# additional parameters
edges <-
  create_edges(
    from = c(1, 2, 3),
    to = c(4, 3, 1),
    rel = "a",
    length = c(50, 100, 250),
    color = "green",
    width = c(1, 5, 2))

# Render the graph to make it viewable in
# the Viewer pane
render_graph(
  create_graph(edges_df = edges),
  output = "visNetwork")

Run the code above in your browser using DataLab