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 8.37 6.19 -> Z1 9.71 5.71 FALSE #> 2 V 8.37 6.19 -> Z2 7.90 4.87 FALSE #> 3 W1 9.93 4.17 -> X 9.73 4.75 FALSE #> 4 W1 9.93 4.17 -> Y 8.82 4.41 FALSE #> 5 W1 9.93 4.17 -> Z1 9.71 5.71 FALSE #> 6 W1 9.93 4.17 <-> W2 8.86 3.76 FALSE #> 7 W2 8.86 3.76 -> X 9.73 4.75 FALSE #> 8 W2 8.86 3.76 -> Y 8.82 4.41 FALSE #> 9 W2 8.86 3.76 -> Z2 7.90 4.87 FALSE #> 10 X 9.73 4.75 -> Y 8.82 4.41 FALSE #> 11 Z1 9.71 5.71 -> X 9.73 4.75 FALSE #> 12 Z2 7.90 4.87 -> Y 8.82 4.41 FALSE #> 13 Y 8.82 4.41 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()