qd_dag: Generate a graph object

View source: R/qd_dag.R

qd_dagR Documentation

Generate a graph object

Description

Provide simple syntax specifying paths between nodes to generate a graph object.

Usage

qd_dag(
  edgelist,
  node.labs = NULL,
  node.aes.opts = list(),
  edge.aes.opts = list(),
  verbose = TRUE,
  check.dag = TRUE,
  theme = "base",
  ...
)

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. See ?node_aes to view available parameters.

edge.aes.opts

A list feeding aesthetic options for edges to DiagrammeR::edge_aes(). Defaults to empty list. See ?edge_aes to view available parameters.

verbose

Indicate whether to print node and edge dataframes to the console. See NOTE 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

Suggestions and bug reports welcome at https://github.com/jrgant/quickDAG/issues.

Packages used: DiagrammeR, stringr, purrr

Note

Leaving the checks option selected 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)
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)
render_graph(g.obj2)



jrgant/quickDAG documentation built on Feb. 15, 2023, 3:20 a.m.