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 15.3 13.8 -> Z1 16.1 12.7 FALSE #> 2 V 15.3 13.8 -> Z2 14.1 13.0 FALSE #> 3 W1 15.3 12.0 -> X 15.5 11.4 FALSE #> 4 W1 15.3 12.0 -> Y 14.3 12.1 FALSE #> 5 W1 15.3 12.0 -> Z1 16.1 12.7 FALSE #> 6 W1 15.3 12.0 <-> W2 14.3 11.5 FALSE #> 7 W2 14.3 11.5 -> X 15.5 11.4 FALSE #> 8 W2 14.3 11.5 -> Y 14.3 12.1 FALSE #> 9 W2 14.3 11.5 -> Z2 14.1 13.0 FALSE #> 10 X 15.5 11.4 -> Y 14.3 12.1 FALSE #> 11 Z1 16.1 12.7 -> X 15.5 11.4 FALSE #> 12 Z2 14.1 13.0 -> Y 14.3 12.1 FALSE #> 13 Y 14.3 12.1 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()