Directed Acyclic Graphs

Authors

[Editor] Hu Zheng;

[Contributors]

Modified

2026-06-05

πŸ€– AI Skill β€” Download the Bizard unified skill for your AI assistant ⬇️ Download Skill ZIP
Note

Hiplot website

This page is the tutorial for source code version of the Hiplot Directed Acyclic Graphs plugin. You can also use the Hiplot website to achieve no code ploting. For more information please see the following link:

https://hiplot.cn/basic/ggdag?lang=en

Visualizing directed acyclic graphs.

Setup

  • System Requirements: Cross-platform (Linux/MacOS/Windows)

  • Programming language: R

  • Dependent packages: ggdag

# Install packages
if (!requireNamespace("ggdag", quietly = TRUE)) {
  install.packages("ggdag")
}

# Load packages
library(ggdag)
sessioninfo::session_info("attached")
─ Session info ───────────────────────────────────────────────────────────────
 setting  value
 version  R version 4.6.0 (2026-04-24)
 os       Ubuntu 24.04.4 LTS
 system   x86_64, linux-gnu
 ui       X11
 language (EN)
 collate  C.UTF-8
 ctype    C.UTF-8
 tz       UTC
 date     2026-05-09
 pandoc   3.1.3 @ /usr/bin/ (via rmarkdown)
 quarto   1.9.37 @ /usr/local/bin/quarto

─ Packages ───────────────────────────────────────────────────────────────────
 package * version date (UTC) lib source
 ggdag   * 0.2.13  2024-07-22 [1] RSPM

 [1] /home/runner/work/_temp/Library
 [2] /opt/R/4.6.0/lib/R/site-library
 [3] /opt/R/4.6.0/lib/R/library
 * ── Packages attached to the search path.

──────────────────────────────────────────────────────────────────────────────

Data Preparation

# Load data
tidy_ggdag <- dagify(
  y ~ x + z2 + w2 + w1,
  x ~ z1 + w1 + w2,
  z1 ~ w1 + v,
  z2 ~ w2 + v,
  w1 ~ ~w2, # bidirected path
  exposure = "x",
  outcome = "y") %>%
  tidy_dagitty()

# View data
head(tidy_ggdag)
$data
# A tibble: 13 Γ— 8
   name       x        y direction to      xend   yend circular
   <chr>  <dbl>    <dbl> <fct>     <chr>  <dbl>  <dbl> <lgl>   
 1 v      1.50   0.00162 ->        z1     0.506 -0.999 FALSE   
 2 v      1.50   0.00162 ->        z2     0.516  1.01  FALSE   
 3 w1    -0.332 -0.489   ->        x     -0.949 -0.569 FALSE   
 4 w1    -0.332 -0.489   ->        y     -0.927  0.598 FALSE   
 5 w1    -0.332 -0.489   ->        z1     0.506 -0.999 FALSE   
 6 w1    -0.332 -0.489   <->       w2    -0.318  0.451 FALSE   
 7 w2    -0.318  0.451   ->        x     -0.949 -0.569 FALSE   
 8 w2    -0.318  0.451   ->        y     -0.927  0.598 FALSE   
 9 w2    -0.318  0.451   ->        z2     0.516  1.01  FALSE   
10 x     -0.949 -0.569   ->        y     -0.927  0.598 FALSE   
11 y     -0.927  0.598   <NA>      <NA>  NA     NA     FALSE   
12 z1     0.506 -0.999   ->        x     -0.949 -0.569 FALSE   
13 z2     0.516  1.01    ->        y     -0.927  0.598 FALSE   

$dag
dag {
v
w1
w2
x [exposure]
y [outcome]
z1
z2
v -> z1
v -> z2
w1 -> x
w1 -> y
w1 -> z1
w1 <-> w2
w2 -> x
w2 -> y
w2 -> z2
x -> y
z1 -> x
z2 -> y
}

Visualization

# Directed Acyclic Graphs
p <- ggdag(tidy_ggdag) +
  theme_dag() 

p
FigureΒ 1: Directed Acyclic Graphs