Skip to content

Instantly share code, notes, and snippets.

@abikoushi
Created August 26, 2025 08:05
Show Gist options
  • Select an option

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

Select an option

Save abikoushi/e5cee1e7eca5d691d0db4b68b0e30204 to your computer and use it in GitHub Desktop.
Plot Causal Diagram using DiagrammeR
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