Tidy a dagitty object

tidy_dagitty(.dagitty, seed = NULL, layout = "nicely", ...)

Arguments

.dagitty

a dagitty

seed

a numeric seed for reproducible layout generation

layout

a layout available in ggraph. See ggraph::create_layout() for details.

...

optional arguments passed to ggraph::create_layout()

Value

a tidy_dagitty object

Examples

library(dagitty) library(ggplot2) dag <- dagitty( "dag { Y <- X <- Z1 <- V -> Z2 -> Y Z1 <- W1 <-> W2 -> Z2 X <- W1 -> Y X <- W2 -> Y X [exposure] Y [outcome] }") tidy_dagitty(dag)
#> # A DAG with 7 nodes and 12 edges #> # #> # Exposure: X #> # Outcome: Y #> # #> # A tibble: 13 x 8 #> name x y direction to xend yend circular #> <chr> <dbl> <dbl> <fct> <chr> <dbl> <dbl> <lgl> #> 1 V 9.78 5.40 -> Z1 9.23 4.09 FALSE #> 2 V 9.78 5.40 -> Z2 8.48 5.96 FALSE #> 3 W1 8.26 4.28 -> X 7.73 3.93 FALSE #> 4 W1 8.26 4.28 -> Y 7.91 5.14 FALSE #> 5 W1 8.26 4.28 -> Z1 9.23 4.09 FALSE #> 6 W1 8.26 4.28 <-> W2 7.29 5.03 FALSE #> 7 W2 7.29 5.03 -> X 7.73 3.93 FALSE #> 8 W2 7.29 5.03 -> Y 7.91 5.14 FALSE #> 9 W2 7.29 5.03 -> Z2 8.48 5.96 FALSE #> 10 X 7.73 3.93 -> Y 7.91 5.14 FALSE #> 11 Z1 9.23 4.09 -> X 7.73 3.93 FALSE #> 12 Z2 8.48 5.96 -> Y 7.91 5.14 FALSE #> 13 Y 7.91 5.14 <NA> <NA> NA NA FALSE
tidy_dagitty(dag, layout = "fr") %>% ggplot(aes(x = x, y = y, xend = xend, yend = yend)) + geom_dag_node() + geom_dag_text() + geom_dag_edges() + theme_dag()