Learn R Programming

DiagrammeR (version 0.7)

create_graph: Create a graph object using data frames representative of nodes and edges

Description

Generates a graph object using data frames for nodes and/or edges; the graph object can be manipulated by other functions.

Usage

create_graph(nodes_df = NULL, edges_df = NULL, graph_attrs = NULL,
  node_attrs = NULL, edge_attrs = NULL, directed = TRUE,
  graph_name = NULL, graph_time = NULL, graph_tz = NULL)

Arguments

nodes_df
an optional data frame containing, at minimum, a column (called nodes) which contains node IDs for the graph. Additional columns (named as Graphviz node attributes) can be included with values for the named node attribute.
edges_df
an optional data frame containing, at minimum, a column (called edge_op) with edge operations as character strings (in the form of [node_id] -> [node_id]). Alternatively, there may be two columns (called from and
graph_attrs
an optional vector of graph attribute statements that can serve as defaults for the graph.
node_attrs
an optional vector of node attribute statements that can serve as defaults for nodes.
edge_attrs
an optional vector of edge attribute statements that can serve as defaults for edges.
directed
with TRUE (the default) or FALSE, either directed or undirected edge operations will be generated, respectively.
graph_name
an optional string for labeling the graph object.
graph_time
a date or date-time string (required for insertion of graph into a graph series of the type temporal).
graph_tz
an optional value for the time zone (tz) corresponding to the date or date-time string supplied as a value to graph_time. If no time zone is provided then it will be set to GMT.

Value

  • a graph object of class dgr_graph.

Examples

Run this code
# Create an empty graph
graph <- create_graph()

# Create a graph with nodes but no edges
nodes <-
  create_nodes(nodes = c("a", "b", "c", "d"),
               label = FALSE,
               type = "lower",
               style = "filled",
               color = "aqua",
               shape = c("circle", "circle",
                         "rectangle", "rectangle"),
               data = c(3.5, 2.6, 9.4, 2.7))

graph <- create_graph(nodes_df = nodes)

# Create a graph with edges but no nodes
edges <-
  create_edges(from = c("a", "b", "c"),
               to = c("d", "c", "a"),
               relationship = "leading_to")

graph <- create_graph(edges_df = edges)

# Create a graph with both nodes and nodes defined, and,
# add some default attributes
graph <- create_graph(nodes_df = nodes,
                      edges_df = edges,
                      node_attrs = "fontname = Helvetica",
                      edge_attrs = c("color = blue",
                                     "arrowsize = 2"))

Run the code above in your browser using DataLab