Last active
June 6, 2026 00:26
-
-
Save abikoushi/c296205d474aa6dc02de53a18962e286 to your computer and use it in GitHub Desktop.
plot DAG 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'] | |
| Z[label = 'Z'] | |
| Y[label = 'Y'] | |
| { rank=same; X; Z; Y; } | |
| U -> X | |
| X -> Z | |
| Z -> 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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment