Learn R Programming

DiagrammeR (version 0.7)

render_graph: Render the graph or output in various formats

Description

Using a dgr_graph object, either render graph in the Viewer or output in various formats.

Usage

render_graph(graph, output = "graph", width = NULL, height = NULL)

Arguments

graph
a dgr_graph object, created using the create_graph function.
output
a string specifying the output type; graph (the default) renders the graph using the grViz function, DOT outputs DOT code for the graph, and SVG provides SVG code for the rendered graph.
width
an optional parameter for specifying the width of the resulting graphic in pixels.
height
an optional parameter for specifying the height of the resulting graphic in pixels.

Examples

Run this code
# Create a graph and then view it in the RStudio Viewer
nodes <-
  create_nodes(nodes = LETTERS,
               type = "letter",
               shape = sample(c("circle", "rectangle"),
                              length(LETTERS),
                              replace = TRUE),
               fillcolor = sample(c("aqua", "gray80",
                                    "pink", "lightgreen",
                                    "azure", "yellow"),
                                  length(LETTERS),
                                  replace = TRUE))

edges <-
  create_edges(from = sample(LETTERS, replace = TRUE),
               to = sample(LETTERS, replace = TRUE),
               relationship = "letter_to_letter")


graph <-
  create_graph(nodes_df = nodes,
               edges_df = edges,
               graph_attrs = "layout = twopi",
               node_attrs = c("fontname = Helvetica",
                              "style = filled"),
               edge_attrs = c("color = gray20",
                              "arrowsize = 0.5"))

render_graph(graph)

Run the code above in your browser using DataLab