Learn R Programming

DiagrammeR (version 0.8.4)

reverse_edge_direction: Reverse the graph's edge direction

Description

Take a directed graph and reverse the edge directions.

Usage

reverse_edge_direction(graph)

Arguments

graph
a graph object of class dgr_graph.

Value

a graph object of class dgr_graph.

Examples

Run this code
library(magrittr)

# Create a graph with a directed tree
graph <-
  create_graph() %>%
  add_balanced_tree(2, 2)

# Reverse the edge directions such that edges
# are directed toward the root of the tree
graph <-
  graph %>% reverse_edge_direction

# Inspect the graph's edges
graph %>% get_edges
#> [1] "2 -> 1" "3 -> 1" "4 -> 2" "5 -> 2" "6 -> 3"
#> [6] "7 -> 3"

Run the code above in your browser using DataLab