Created
June 6, 2026 12:06
-
-
Save abikoushi/520ae7e8eddcf711099f998491436daa to your computer and use it in GitHub Desktop.
plot DAG for instruments variable method using DiagrammeR
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', shape=circle] | |
| X[label = 'X'] | |
| Y[label = 'Y'] | |
| { rank=same; X; Y; } | |
| U -> X | |
| X -> Y | |
| U -> Y | |
| }") | |
| print(g1) | |
| rsvg_png(charToRaw(export_svg(g1)), | |
| "graph1.png", | |
| width = 500, height = 500) | |
| g2 <- grViz("digraph{ | |
| node[shape = plaintext] | |
| U[label = 'U', shape=circle] | |
| X[label = 'X'] | |
| Z[label = 'Z'] | |
| Y[label = 'Y'] | |
| { rank=same; X; Z; Y; } | |
| U -> X | |
| Z -> X | |
| X -> Y | |
| U -> Y | |
| }") | |
| print(g2) | |
| rsvg_png(charToRaw(export_svg(g2)), | |
| "graph2.png", | |
| width = 500, height = 500) | |
| g2_post <- grViz("digraph{ | |
| node[shape = plaintext] | |
| U[label = 'U', shape=circle] | |
| X[label = 'X'] | |
| Y[label = 'Y'] | |
| { rank=same; X; Y; } | |
| X -> Y | |
| U -> Y | |
| }") | |
| print(g2_post) | |
| rsvg_png(charToRaw(export_svg(g2_post)), | |
| "graph3.png", | |
| width = 500, height = 500) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment