as_tidy_dagitty: Convert objects into 'tidy_dagitty' objects

View source: R/tidy_dag.R

as_tidy_dagittyR Documentation

Convert objects into tidy_dagitty objects

Description

An alternative API and specification to tidy_dagitty(), as_tidy_dagitty() allows you to create tidy_dagitty objects from data frames. There is also a method for dagitty objects, which is a thin wrapper for tidy_dagitty(). To create a DAG from a data frame, it must contain name and to columns, representing the nodes and any edges leading from the nodes. If there are x, y, xend, and yend columns, they will be used as coordinates. Otherwise, layout will be used. See tidy_dagitty for more information about layouts. Additionally, you can specify status (one of exposure, outcome, or latent) by including a status column. Any other columns in the data set will also be joined to the tidy_dagitty data.

Usage

as_tidy_dagitty(x, ...)

## S3 method for class 'dagitty'
as_tidy_dagitty(x, seed = NULL, layout = "nicely", ...)

## S3 method for class 'data.frame'
as_tidy_dagitty(x, seed = NULL, layout = "nicely", ...)

Arguments

x

An object to convert into a tidy_dagitty. Currently supports dagitty and data.frame objects.

...

optional arguments passed to ggraph::create_layout()

seed

a numeric seed for reproducible layout generation

layout

a layout available in ggraph. See ggraph::create_layout() for details. Alternatively, "time_ordered" will use time_ordered_coords() to algorithmically sort the graph by time.

Value

a tidy_dagitty object

See Also

tidy_dagitty(), pull_dag()

Examples


data.frame(name = c("c", "c", "x"), to = c("x", "y", "y")) %>%
  as_tidy_dagitty()


ggdag documentation built on Sept. 11, 2024, 6:12 p.m.