makeDAG: Output, view, or embed DAGs.

View source: R/makeDAG.R

makeDAGR Documentation

Output, view, or embed DAGs.

Description

Save directed acyclic graphs (DAGs) generated in DiagrammeR and export them to pdf, png, or svg format. Users may optionally choose to view the DAG without saving or to embed it in an RMarkdown document.

Usage

makeDAG(
  graphcode = NULL,
  dagname = NULL,
  filetype = "pdf",
  text.nodes = NULL,
  box.nodes = NULL,
  solid.edges = NULL,
  dashed.edges = NULL,
  footnotes = NULL,
  direction = "LR",
  embed = FALSE,
  ...
)

Arguments

graphcode

Partial graphViz code object, which will give you the most control over the appearance of your DAG.

dagname

A path with which to name your DAG file, if filetype set to output format (see below).

filetype

Output file format. Select from pdf, png, svg, or view. Setting the option to view will not save a file but will generate the diagram in your viewer. Defaults to pdf.

text.nodes

A string containing the plain text nodes, separated by spaces.

box.nodes

A string containing the boxed nodes, separated by spaces.

solid.edges

A string specifying the paths you want to draw between measured covariates. Example: "Alcohol -> Smoking Smoking -> Cancer".

dashed.edges

A string specifying paths containing unmeasured covariates.

footnotes

Add a footnote to the bottom of the graph.

direction

Specify the direction of diagram flow. Defaults to "LR", for left-right.

embed

For use within R chunks in RMarkdown only. You will probably want to have the echo chunk option set to FALSE, unless you want to display the R code itself. The embed defaults to TRUE.

...

Pass arguments to interior functions for PNG or SVG files. For instance, specify height and width arguments.

Note

This is not a true DAG package in the sense that it will not prevent the inclusion of feedback loops or bidirectional arrows. It's meant mostly to create reasonable-looking DAGs quickly and easily with a minimum of layout or formatting code. DiagrammeR in general does a pretty good job at layout. Those interested in DAGs might check out other R packages like dagR or dagitty, both of which I've yet to explore in detail.

Suggestions and issue reports welcome at https://github.com/jrgant/quickDAG/issues!

References

A fair amount of the heavy lifting here is done thanks to code snippets from users HJAllen and puterleat on the following thread: https://github.com/rich-iannone/DiagrammeR/issues/133

Packages used: DiagrammeR, DiagrammeRsvg, rsvg

Examples

# Using your own graph code

# Examples have been removed, as makeDAG() is now deprecated.


jrgant/quickDAG documentation built on Feb. 15, 2023, 3:20 a.m.