Skip to contents

Creates a styled causal directed acyclic graph (DAG) for visualizing assumed causal structures. Wraps dagitty and ggdag (if available) to produce publication-ready DAG figures with highlighted backdoor paths, adjustment sets, and treatment/outcome nodes.

Usage

dag_plot(
  dag_string,
  exposure = NULL,
  outcome = NULL,
  layout = c("auto", "circle", "star", "tree"),
  show_adjustment_set = TRUE,
  show_paths = FALSE,
  title = NULL,
  node_size = 14
)

Arguments

dag_string

Character. A dagitty DAG specification string, e.g. "dag{ X -> Y; Z -> X; Z -> Y }". Can also be a dagitty object.

exposure

Character. Name of the treatment/exposure node.

outcome

Character. Name of the outcome node.

layout

Character. Layout algorithm. One of "circle", "star", "tree", "auto". Default "auto".

show_adjustment_set

Logical. Highlight a minimal adjustment set. Default TRUE.

show_paths

Logical. Annotate causal paths. Default FALSE.

title

Character. Plot title. Default NULL.

node_size

Numeric. Node size for ggdag. Default 14.

Value

A ggplot2 object. If neither dagitty nor ggdag is installed, returns the raw dag_string invisibly with a message.

References

Textor, J., van der Zander, B., Gilthorpe, M. S., Liskiewicz, M., & Ellison, G. T. (2016). Robust causal inference using directed acyclic graphs: the R package 'dagitty'. International Journal of Epidemiology, 45(6), 1887-1894.

Examples

dag_plot(
  dag_string = "dag{ X -> Y; Z -> X; Z -> Y }",
  exposure   = "X",
  outcome    = "Y",
  title      = "Simple Confounded DAG"
)
#> Warning: No shared levels found between `names(values)` of the manual scale and the
#> data's fill values.