set_df_as_edge_attr {DiagrammeR} | R Documentation |
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.
set_df_as_edge_attr(graph, edge, df)
graph |
a graph object of class
|
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. |
a graph object of class dgr_graph
.
# 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 <- set_df_as_edge_attr( graph = graph, edge = 1, df = df)