Skip to contents

Takes an input graph with bidirected edges and replaces every bidirected edge x <-> y with a substructure x <- L -> y, where L is a latent variable. See dagitty::canonicalize() for details. Undirected edges are not currently supported in ggdag.

Usage

node_canonical(.dag, ...)

ggdag_canonical(
  .tdy_dag,
  ...,
  edge_type = "link_arc",
  node_size = 16,
  text_size = 3.88,
  label_size = text_size,
  text_col = "white",
  label_col = text_col,
  use_edges = TRUE,
  use_nodes = TRUE,
  use_stylized = FALSE,
  use_text = TRUE,
  use_labels = NULL,
  label = NULL,
  text = NULL,
  node = deprecated(),
  stylized = deprecated()
)

Arguments

.dag, .tdy_dag

input graph, an object of class tidy_dagitty or dagitty

...

additional arguments passed to tidy_dagitty()

edge_type

The type of edge, one of "link_arc", "link", "arc", "diagonal".

node_size

The size of the nodes.

text_size

The size of the text.

label_size

The size of the labels.

text_col

The color of the text.

label_col

The color of the labels.

use_edges

A logical value. Include a geom_dag_edges*() function? If TRUE, which is determined by edge_type.

use_nodes

A logical value. Include geom_dag_point()?

use_stylized

A logical value. Include geom_dag_node()?

use_text

A logical value. Include geom_dag_text()?

use_labels

A logical value. Include geom_dag_label_repel()?

label

The bare name of a column to use for geom_dag_label_repel(). If use_labels = TRUE, the default is to use label.

text

The bare name of a column to use for geom_dag_text(). If use_text = TRUE, the default is to use name.

node

Deprecated.

stylized

Deprecated.

Value

a tidy_dagitty that includes L or a ggplot

Examples

dag <- dagify(y ~ x + z, x ~ ~z)

ggdag(dag)


node_canonical(dag)
#> # A DAG with 4 nodes and 4 edges
#> #
#> # Latent Variable: L1
#> #
#> # A tibble: 5 × 8
#>   name       x      y direction to      xend   yend circular
#>   <chr>  <dbl>  <dbl> <fct>     <chr>  <dbl>  <dbl> <lgl>   
#> 1 L1    -0.338 -1.11  ->        x      0.462 -0.295 FALSE   
#> 2 L1    -0.338 -1.11  ->        z     -1.17  -0.326 FALSE   
#> 3 x      0.462 -0.295 ->        y     -0.369  0.492 FALSE   
#> 4 y     -0.369  0.492 NA        NA    NA     NA     FALSE   
#> 5 z     -1.17  -0.326 ->        y     -0.369  0.492 FALSE   
ggdag_canonical(dag)