Created
August 26, 2025 08:05
-
-
Save abikoushi/e5cee1e7eca5d691d0db4b68b0e30204 to your computer and use it in GitHub Desktop.
Plot Causal Diagram 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) | |
| #https://elevanth.org/blog/2021/06/21/regression-fire-and-dangerous-things-2-3/ | |
| g <- grViz("digraph{ | |
| node[shape = plaintext] | |
| U[label = 'U', shape=circle] | |
| B1[label = 'B1'] | |
| B2[label = 'B2'] | |
| M[label = 'M', fontcolor='red'] | |
| D[label = 'D', fontcolor='blue'] | |
| edge[color = black] | |
| B1 -> M | |
| B2 -> D | |
| U -> M | |
| U -> D | |
| M -> D | |
| }") | |
| print(g) | |
| rsvg_png(charToRaw(export_svg(g)), | |
| "graph.png", | |
| width = 700, height = 700) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment