Learn R Programming

DiagrammeR (version 0.8.4)

add_edge: Add an edge between nodes in a graph object

Description

With a graph object of class dgr_graph, add an edge to nodes within the graph.

Usage

add_edge(graph, from, to, rel = NULL)

Arguments

graph
a graph object of class dgr_graph that is created using create_graph.
from
the outgoing node from which the edge is connected.
to
the incoming nodes to which each edge is connected.
rel
an optional string specifying the relationship between the connected nodes.

Value

a graph object of class dgr_graph.

Examples

Run this code
library(magrittr)

# Create a graph with two nodes
graph <-
  create_graph() %>%
  add_n_nodes(2)

# Add an edge between those nodes and attach a
# relationship to the edge
graph <-
 add_edge(
   graph,
   from = 1,
   to = 2,
   rel = "to_get")

# Use the `edge_info()` function to verify that
# the edge has been created
edge_info(graph)
#>   from to    rel
#> 1    1  2 to_get

Run the code above in your browser using DataLab