Dag-plot.R

#' Directed Acyclic Graphs
#' 
#' 
library(ggplot2)
#library(patchwork)
library(ggdag)
library(dagitty)
theme_set(theme_dag_blank())

king_mod <- dagify(lncelld ~ PI + Diuron, 
                   PI ~ Light + Diuron) 

g1 <- ggdag(king_mod, 
            text_size = 2,
            node_size = 12) 

g1


dagify(y ~ x + z, x ~ z)

coords <- list(
  x = c(A = 1, B = 2, D = 3, C = 3, F = 3, E = 4, G = 5, H = 5, I = 5),
  y = c(A = 0, B = 0, D = 1, C = 0, F = -1, E = 0, G = 1, H = 0, I = -1)
)

dag <- dagify(G ~ ~H,
              G ~ ~I,
              I ~ ~G,
              H ~ ~I,
              D ~ B,
              C ~ B,
              I ~ C + F,
              F ~ B,
              B ~ A,
              H ~ E,
              C ~ E + G,
              G ~ D,
              coords = coords
)

dagitty::is.dagitty(dag)

ggdag(dag)

dag2 <- dagify(y ~ x + z2 + w2 + w1,
               x ~ z1 + w1,
               z1 ~ w1 + v,
               z2 ~ w2 + v,
               w1 ~ ~w2,
               exposure = "x",
               outcome = "y"
)

ggdag(dag2)
stp4/stp25plot documentation built on March 29, 2025, 4:26 p.m.