Provide simple syntax specifying paths between nodes to generate a graph object.
Arguments
- edgelist
A vector of edge relationships. Must be strictly organized (see example for format).
- node_labs
A named character vector containing label names. Defaults to `NULL`.
- node_aes_opts
A list feeding aesthetic options for nodes to [DiagrammeR::node_aes()]. Defaults to empty list.
- edge_aes_opts
A list feeding aesthetic options for edges to [DiagrammeR::edge_aes()]. Defaults to empty list.
- verbose
Indicate whether to print node and edge dataframes to the console. See Details below. Defaults to `TRUE`.
- check_dag
Logical. Check whether the graph conforms to the rules of DAGs. Defaults to `TRUE`.
- theme
Choose theme for plot output. Defaults to `"base"`. Setting theme to `NULL` will use DiagrammeR's `NULL` attribute theme.
- ...
Pass optional `conditioned` argument to [qd_themes()].
Details
Leaving the `verbose` set to `TRUE` may be advisable to ensure labels and IDs have not been mismatched. By default, [qd_dag()] alphabetizes nodes included in `edgelist` and does the same for `node_labs` under a first assumption that labels will begin with the same letter as their corresponding `alpha_id`, which may not always be the case.
Examples
# Provide a list of edges, with nodes specified as letters.
# Do not list a node as a parent more than once.
# Each line should contain a single edge character '->'.
edges <- c("A -> { B C }",
"B -> C")
# make a DAG object and render the graph using the default theme
g.obj <- qd_dag(edges)
#>
#>
#> CHECKED: The diagram is a DAG.
#> -------------------------------------------------------------------------
#> Make sure everything is matched up properly!
#> To stop printing data to the console, set 'verbose' to FALSE.
#> -------------------------------------------------------------------------
#> ........................ NODE DATAFRAME ........................
#>
#> id type label alpha_id
#> 1 1 <NA> A A
#> 2 2 <NA> B B
#> 3 3 <NA> C C
#>
#> ........................ EDGE DATAFRAME ........................
#>
#> id from to rel
#> 1 1 1 2 <NA>
#> 2 2 1 3 <NA>
#> 3 3 2 3 <NA>
DiagrammeR::render_graph(g.obj)
# Pass labels and aesthetic options for nodes or edges
g.obj2 <- qd_dag(edges,
node_labs = c("A" = "Alcohol",
"B" = "BP",
"C" = "CVD"),
node_aes_opts = list(shape = "plaintext",
fillcolor = "none",
color = "black"),
edge_aes_opts = list(arrowsize = 0.5,
color = "gray"),
theme = NULL)
#>
#>
#> CHECKED: The diagram is a DAG.
#> -------------------------------------------------------------------------
#> Make sure everything is matched up properly!
#> To stop printing data to the console, set 'verbose' to FALSE.
#> -------------------------------------------------------------------------
#> ........................ NODE DATAFRAME ........................
#>
#> id type label shape fillcolor color alpha_id
#> 1 1 <NA> Alcohol plaintext none black A
#> 2 2 <NA> BP plaintext none black B
#> 3 3 <NA> CVD plaintext none black C
#>
#> ........................ EDGE DATAFRAME ........................
#>
#> id from to rel arrowsize color
#> 1 1 1 2 <NA> 0.5 gray
#> 2 2 1 3 <NA> 0.5 gray
#> 3 3 2 3 <NA> 0.5 gray
DiagrammeR::render_graph(g.obj2)