Learn R Programming

DOT (version 0.1)

dot: Render and Export DOT Graphs in R

Description

Graph Description Language (DOT) is a simplified and intuitive plain text graphical language. The dot() function renders the DOT markup language in R and also provides the possibility to export the graphs in PostScript and SVG (Scalable Vector Graphics) formats. In addition, it supports literate programming packages such as Knitr and R2HTML. Visit http://haghish.com/dot for downloading examples of creating algorithms and several graphs for Rmarkdown and R HTML to generate dynamic procedural graphs in dynamic documents using the DOT package.

Usage

dot(DOT, file = NULL, return = "auto")

Arguments

DOT
This argument takes a string containing the DOT script. It is advised to use single quotation mark for the DOT string since the script often includes double quotations which can crash the function.
file
defines the file name for exporting the graph. The acceptable file extensions are "ps" for PostScript and "svg" for SVG format (see examples below).
return
specifies if PS or SVG script should be printed in R console. The acceptable values are "auto", "cat", "verbatim", and NULL. The default value is "auto" which does not return anything unless the dot() function is called within 'knitr' or 'rmarkdown' packages, which require concatenated graphical script. The "cat" returns concatenated PS or SVG script, printed in multiple lines in the R console. The "verbatim" returns a single string which is assignable to an object.

Value

By default, the function only renders and loads the DOT plot in RStudio but does not return any PS or SVG script. If the return argument is specified, it returns PostScript or SVG script. Note that for assigning the script returned from dot() to an object, only "verbatim" value can be used to create a string object.

Examples

Run this code
#create a simple DOT graph and load it in RStudio
dot("digraph {A -> B;}")

#to produce a dynamic document including a diagram in 'rmarkdown'
## Not run: 
# ```{r echo=FALSE, results='asis'}
# library(DOT)
# dot("digraph {A -> B;}", return = "cat")
# ```## End(Not run)


#create a DOT graph and export a SVG file to the working directory
dot("digraph {A -> B; B -> C; B -> D;}", file = "myfile.svg")

#export the example above in PostScript format
dot("digraph {A -> B; B -> C; B -> D;}", file = "myfile.ps")

#create a DOT graph and save the script in a string object in R
myString <- dot("digraph {A -> B;}", return = "verbatim")

Run the code above in your browser using DataLab