Created
June 26, 2026 08:09
-
-
Save abikoushi/5203efdfd0d1d0d70a42e355ebada9d5 to your computer and use it in GitHub Desktop.
plot DAG for negative control variable using R
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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