Skip to contents

Renders a digraph view of a theory without leaving R. Where tf_diagram() returns the deterministic Graphviz DOT string, tf_render_diagram() passes that string to the DiagrammeR engine and returns either an interactive widget, which displays in the RStudio viewer and in R Markdown documents, or a standalone SVG string, ready to embed in a page or save to a file.

Usage

tf_render_diagram(x, type = "nomological_net", as = c("widget", "svg"))

Arguments

x

A theory object (named list), or a diagram IR string from tf_diagram() or tf_lit_diagram(), so literature diagrams render the same way.

type

The diagram type, as in tf_diagram(). Ignored when x is already an IR string.

as

Either "widget" (default), for display in the viewer and in R Markdown, or "svg", a standalone SVG string.

Value

With as = "widget", an htmlwidget for a DOT view, or a browsable htmltools HTML object for the venn, rigour and severity views. With as = "svg", a single SVG string.

Details

The three chart views (venn, rigour and severity) are already SVG, so they are returned as-is under as = "svg" and wrapped for display under as = "widget". The causal_dag view emits dagitty syntax rather than DOT, so it is not rendered here. Paste it into a dagitty tool or the dagitty R package instead.

The DOT views need the suggested DiagrammeR package, and as = "svg" also needs DiagrammeRsvg. The chart views need neither, but showing one under as = "widget" needs htmltools. A missing package stops with a message naming it.

See also

tf_diagram() for the intermediate representation itself, which needs no optional packages and is identical in R and in Python.

Examples

theory <- tf_theory("demo-1", "A demonstration theory") |>
  tf_add_construct("c_arousal", "Arousal", "Bodily activation.") |>
  tf_add_construct("c_threat", "Perceived threat", "Appraised danger.") |>
  tf_add_proposition("p1", "c_arousal", "c_threat", "causes")
tf_render_diagram(theory, "nomological_net")