DiagrammeR (version 0.9.2)

set_df_as_node_attr: Set a data frame as a node attribute

Description

From a graph object of class dgr_graph, bind a data frame as a node attribute property for one given graph node. The data frames are stored in list columns within a df_tbl 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_node_attr(graph, node, df)

Arguments

graph

a graph object of class dgr_graph.

node

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

df

the data frame to be bound to the node 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
# a node attribute
df <-
  data.frame(
    a = c("one", "two", "three"),
    b = c(1, 2, 3),
    stringsAsFactors = FALSE)

# Bind the data frame as a node attribute
# of node `1`
graph <-
  set_df_as_node_attr(
    graph = graph,
    node = 1,
    df = df)

# Create another data frame to add as
# a node attribute
df_2 <-
  data.frame(
    c = c("four", "five", "six"),
    d = c(4, 5, 6),
    stringsAsFactors = FALSE)

# Bind the data frame as a node attribute
# of node `2`
graph <-
  set_df_as_node_attr(
    graph = graph,
    node = 2,
    df = df_2)
# }

Run the code above in your browser using DataLab