DiagrammeR (version 1.0.5)

set_df_as_edge_attr: Set a data frame as an edge attribute

Description

From a graph object of class dgr_graph, bind a data frame as an edge attribute property for one given graph edge. The data frames are stored in list columns within a df_tbl object, itself residing within the graph object. A df_id value is generated and serves as a pointer to the table row that contains the ingested data frame.

Usage

set_df_as_edge_attr(graph, edge, df)

Arguments

graph

A graph object of class dgr_graph.

edge

The edge ID to which the data frame will be bound as an attribute.

df

The data frame to be bound to the edge as an attribute.

Value

A graph object of class dgr_graph.

Examples

Run this code
# NOT RUN {
# Create a node data frame (ndf)
ndf <-
  create_node_df(
    n = 4,
    type = "basic",
    label = TRUE,
    value = c(3.5, 2.6, 9.4, 2.7))

# Create an edge data frame (edf)
edf <-
  create_edge_df(
    from = c(1, 2, 3),
    to = c(4, 3, 1),
    rel = "leading_to")

# Create a graph
graph <-
  create_graph(
    nodes_df = ndf,
    edges_df = edf)

# Create a simple data frame to add as
# an edge attribute
df <-
  data.frame(
    a = c("one", "two", "three"),
    b = c(1, 2, 3),
    stringsAsFactors = FALSE)

# Bind the data frame as an edge attribute
# to the edge with ID `1`
graph <-
  graph %>%
  set_df_as_edge_attr(
    edge = 1,
    df = df)

# }

Run the code above in your browser using DataCamp Workspace