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 13.5 10.1 -> Z1 14.6 9.29 FALSE #> 2 V 13.5 10.1 -> Z2 12.6 9.00 FALSE #> 3 W1 14.0 8.43 -> X 14.4 7.86 FALSE #> 4 W1 14.0 8.43 -> Y 13.0 8.12 FALSE #> 5 W1 14.0 8.43 -> Z1 14.6 9.29 FALSE #> 6 W1 14.0 8.43 <-> W2 13.3 7.59 FALSE #> 7 W2 13.3 7.59 -> X 14.4 7.86 FALSE #> 8 W2 13.3 7.59 -> Y 13.0 8.12 FALSE #> 9 W2 13.3 7.59 -> Z2 12.6 9.00 FALSE #> 10 X 14.4 7.86 -> Y 13.0 8.12 FALSE #> 11 Z1 14.6 9.29 -> X 14.4 7.86 FALSE #> 12 Z2 12.6 9.00 -> Y 13.0 8.12 FALSE #> 13 Y 13.0 8.12 <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()