Learn R Programming

DiagrammeR (version 0.6)

grViz: R + viz.js

Description

Make diagrams in R using https://github.com/mdaines/viz.js{viz.js} with infrastructure provided by http://www.htmlwidgets.org/{htmlwidgets}.

Usage

grViz(diagram = "", engine = "dot", allow_subst = TRUE, options = NULL,
  width = NULL, height = NULL)

Arguments

diagram
http://graphviz.org{graphviz} spec for a diagram as either text, filename string, or file connection
engine
string for the Graphviz layout engine; can be "dot" (default), "neato", "circo", or "twopi". For more information see viz.js Usage{https://github.com/mdaines/viz.js#usage}.
allow_subst
a boolean that enables/disables subsitution functionality.
options
parameters supplied to the htmlwidgets framework.
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.

Value

  • An object of class htmlwidget that will intelligently print itself into HTML in a variety of contexts including the R console, within R Markdown documents, and within Shiny output bindings.

Examples

Run this code
# A very simple example
grViz("digraph {A;}")

# A slightly more involved example
#  using example from http://www.graphviz.org/pdf/dotguide.pdf
#    "Drawing graphs with dot"
#    Emden R. Gansner and Eleftherios Koutsofios and Stephen North
#    January 5, 2015
grViz('
digraph G {
      size = "4,4";
      main [shape = box]; /* this is a comment */
      main -> parse [weight = 8];
      parse -> execute;
      main -> init [style = dotted];
      main -> cleanup;
      execute -> { make_string; printf}
      init -> make_string;
      edge [color = red]; // so is this
      main -> printf;
      node [shape = box, style = filled, color = ".7 .3 1.0"];
      execute -> compare;
}
')

Run the code above in your browser using DataLab