Skip to content

Instantly share code, notes, and snippets.

@abikoushi
Created June 26, 2026 08:09
Show Gist options
  • Select an option

  • Save abikoushi/5203efdfd0d1d0d70a42e355ebada9d5 to your computer and use it in GitHub Desktop.

Select an option

Save abikoushi/5203efdfd0d1d0d70a42e355ebada9d5 to your computer and use it in GitHub Desktop.
plot DAG for negative control variable using R
library(DiagrammeR)
library(DiagrammeRsvg)
library(rsvg)
g1 <- grViz("digraph{
node[shape = plaintext]
U[label = 'U']
L[label = 'L']
A[label = 'A']
Y[label = 'Y']
U -> L[arrowhead=none, style=dashed]
U -> A
L -> A
A -> Y
U -> Y
L -> Y
}")
print(g1)
rsvg_png(charToRaw(export_svg(g1)),
"graph1.png",
width = 500, height = 500)
g2 <- grViz("digraph{
node[shape = plaintext]
U[label = 'U']
L[label = 'L']
A[label = 'A']
Y[label = 'Y']
U -> L[arrowhead=none, style=dashed]
U -> N
L -> N
U -> A
L -> A
A -> Y
U -> Y
L -> Y
}")
print(g2)
rsvg_png(charToRaw(export_svg(g2)),
"graph2.png",
width = 500, height = 500)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment