add_edges_from_table {DiagrammeR}R Documentation

Add edges and attributes to graph from a table

Description

Add edges and their attributes to an existing graph object from data in a CSV file or a data frame.

Usage

add_edges_from_table(graph, table, from_col, from_mapping = NULL, to_col,
  to_mapping = NULL, set_rel = NULL, select_cols = NULL,
  drop_cols = NULL, rename_attrs = NULL, rel_col = NULL)

Arguments

graph

a graph object of class dgr_graph that is created using create_graph.

table

either a path to a CSV file, or, a data frame object.

from_col

the name of the table column from which edges originate.

from_mapping

a single character value for the mapping of a column in the external table (supplied as from_col) to a column in the graph's internal node data frame (ndf).

to_col

the name of the table column to which edges terminate.

to_mapping

a single character value for the mapping of a column in the external table (supplied as to_col) to a column in the graph's internal node data frame (ndf).

set_rel

an optional string to apply a rel attribute to all edges created from the table records.

select_cols

an optional character vector for specifying which columns in the table that should be imported as edge attributes.

drop_cols

an optional character vector for dropping columns from the incoming data.

rename_attrs

an optional character vector for renaming edge attributes.

rel_col

an option to apply a column of data in the table as rel attribute values.

Value

a graph object of class dgr_graph.

Examples

## Not run: 
library(magrittr)
library(dplyr)

# Create a graph from a CSV file
graph <- create_graph() %>%
add_edges_from_table(
  system.file("examples/projects_and_contributors.csv",
              package = "DiagrammeR"),
  from_col = "contributor_name",
  to_col = "project_name",
  rel_col = "contributor_role",
  set_rel = "contributes_to")

# Get a count of nodes in the graph
node_count(graph)
#> [1] 13

# Get a count of edges in the graph
edge_count(graph)
#> [1] 13

## End(Not run)

[Package DiagrammeR version 0.8.4 Index]