| Title: | Make Beautiful Directed Acyclic Graphs |
|---|---|
| Description: | This package allows the user the save directed acyclic graphs (DAGs) generated in DiagrammeR and export them to PDF, PNG, SVG, or PS format. Users may optionally choose to view the DAG without saving or to embed it in a document. In addition, quickdag allows the user easily to reformat DAGs as single-world intervention graph (SWIG) templates. |
| Authors: | Jason Gantenberg [aut, cre] (ORCID: <https://orcid.org/0000-0002-8144-4273>) |
| Maintainer: | Jason Gantenberg <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.2.1.9000 |
| Built: | 2026-05-20 06:23:29 UTC |
| Source: | https://github.com/jrgant/quickdag |
Retrieves numeric IDs given alphanumeric IDs
get_numids(graph_obj, alpha_ids)get_numids(graph_obj, alpha_ids)
graph_obj |
|
alpha_ids |
A vector of alphanumeric node IDs upon which to operate. |
Parse edges in a graph specification
parse_edgestring(edgestring) parse_edges(edgelist)parse_edgestring(edgestring) parse_edges(edgelist)
edgestring |
A single string containing some set of node-edge relationships |
edgelist |
A vector of node-edge relationships. |
Parse nodes
parse_nodes(edgelist)parse_nodes(edgelist)
edgelist |
A vector of node-edge relationships. |
Format an edgelist and send it to dagitty to identify variable adjustment sets.
qd_adjustment_sets( edgelist, diagram_type = "dag", showplot = FALSE, exposure, outcome, ... ) qd_todagitty( edgelist, diagram_type = "dag", showplot = FALSE, exposure, outcome, ... )qd_adjustment_sets( edgelist, diagram_type = "dag", showplot = FALSE, exposure, outcome, ... ) qd_todagitty( edgelist, diagram_type = "dag", showplot = FALSE, exposure, outcome, ... )
edgelist |
A vector of edge relationships. |
diagram_type |
Character identifying the diagram type. Defaults to "dag", but
user can specify another graph type (see |
showplot |
Logical indicating whether to produce a dagitty plot. Defaults to
|
exposure |
Character. Specify exposure of interest. (Required) |
outcome |
Character. Specifiy outcome of interest. (Required) |
... |
Pass arguments to |
The exposure and outcome options map to dagitty parameters of the same name.
qd_todagitty() remains an alias for qd_adjustment_sets() to avoid breaking
existing scripts, as it was the original name of this function.
# feed an edgelist to qd_adjustment_sets() edges <- c("A -> { B C D }", "B -> C", "E -> { B C }", "Y <- L -> A") qd_adjustment_sets(edges, exposure = "A", outcome = "C") qd_adjustment_sets(edges, exposure = "A", outcome = "C", type = "minimal") # if you've already created a qd_dag() object dag <- qd_dag(edges) qd_adjustment_sets(dag$qd_edgelist, exposure = "A", outcome = "Y")# feed an edgelist to qd_adjustment_sets() edges <- c("A -> { B C D }", "B -> C", "E -> { B C }", "Y <- L -> A") qd_adjustment_sets(edges, exposure = "A", outcome = "C") qd_adjustment_sets(edges, exposure = "A", outcome = "C", type = "minimal") # if you've already created a qd_dag() object dag <- qd_dag(edges) qd_adjustment_sets(dag$qd_edgelist, exposure = "A", outcome = "Y")
Provide simple syntax specifying paths between nodes to generate a graph object.
qd_dag( edgelist, node_labs = NULL, node_aes_opts = list(), edge_aes_opts = list(), format_special = getOption("quickdag.format_special"), verbose = getOption("quickdag.verbose"), check_dag = getOption("quickdag.check_dag"), theme = getOption("quickdag.theme"), ... )qd_dag( edgelist, node_labs = NULL, node_aes_opts = list(), edge_aes_opts = list(), format_special = getOption("quickdag.format_special"), verbose = getOption("quickdag.verbose"), check_dag = getOption("quickdag.check_dag"), theme = getOption("quickdag.theme"), ... )
edgelist |
A vector of node-edge relationships. |
node_labs |
A named character vector containing label names. Defaults
to |
node_aes_opts |
A list feeding aesthetic options for nodes to
|
edge_aes_opts |
A list feeding aesthetic options for edges to
|
format_special |
Render numeric elements in an alphanumeric |
verbose |
Indicate whether to print node and edge dataframes to the console.
See Details below. Defaults to |
check_dag |
Logical. Check whether the graph conforms to the rules of DAGs.
Defaults to |
theme |
Choose theme for plot output. Defaults to |
... |
Pass optional |
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.
# Provide a list of edges, with nodes specified as letters or single words. edges <- c("A -> { B C } <- L", "B -> C") # Make a DAG object and render the graph using the default theme g.obj <- qd_dag(edges) 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", "L" = "State"), node_aes_opts = list(shape = "plaintext", fillcolor = "none", color = "black"), edge_aes_opts = list(arrowsize = 0.5, color = "gray"), theme = NULL) DiagrammeR::render_graph(g.obj2)# Provide a list of edges, with nodes specified as letters or single words. edges <- c("A -> { B C } <- L", "B -> C") # Make a DAG object and render the graph using the default theme g.obj <- qd_dag(edges) 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", "L" = "State"), node_aes_opts = list(shape = "plaintext", fillcolor = "none", color = "black"), edge_aes_opts = list(arrowsize = 0.5, color = "gray"), theme = NULL) DiagrammeR::render_graph(g.obj2)
qd_save() is a light wrapper around DiagrammeR::export_graph(), which
enables exporting high-quality and/or scalable graphics for both print and online.
For convenience in computational notebooks like quarto or RMarkdown documents,
qd_save() also allows the user to embed the image via knitr::include_graphics().
qd_save(graph, file_name, ..., embed = getOption("quickdag.embed"), kg = NULL)qd_save(graph, file_name, ..., embed = getOption("quickdag.embed"), kg = NULL)
graph |
A graph object produced by |
file_name |
A filename (possibly including a path) to which to save the image.
File type will be determined by the extension provided (pdf, svg, png, ps). See
|
... |
Pass other arguments to |
embed |
Defaults to |
kg |
A list allowing the user to set arguments for |
# redirect file to temporary directory (example only) file <- file.path(tempdir(), "dag.pdf") # save without embedding dag <- qd_dag(c("L -> {A Y}", "A -> Y"), check_dag = FALSE, verbose = FALSE) qd_save(dag, file) # embed from code chunk using knitr::include_graphics() qd_save(dag, file, embed = TRUE) # `title` passed to DiagrammeR::export_graph() qd_save(dag, file, title = "Demo") # clean up temporary directory file.remove(file)# redirect file to temporary directory (example only) file <- file.path(tempdir(), "dag.pdf") # save without embedding dag <- qd_dag(c("L -> {A Y}", "A -> Y"), check_dag = FALSE, verbose = FALSE) qd_save(dag, file) # embed from code chunk using knitr::include_graphics() qd_save(dag, file, embed = TRUE) # `title` passed to DiagrammeR::export_graph() qd_save(dag, file, title = "Demo") # clean up temporary directory file.remove(file)
Graph operations
qd_set_node_attrs(graph_obj, ..., alpha_ids) qd_set_edge_attrs(graph_obj, ..., from_alpha = NULL, to_alpha = NULL) select_nodes_by_alpha_id(graph_obj, alpha_ids, set_op = "union") qd_select_nodes(graph_obj, alpha_ids, set_op = "union") select_edges_by_node_alpha_id(graph_obj, alpha_ids, set_op = "union") qd_select_edges(graph_obj, alpha_ids, set_op = "union")qd_set_node_attrs(graph_obj, ..., alpha_ids) qd_set_edge_attrs(graph_obj, ..., from_alpha = NULL, to_alpha = NULL) select_nodes_by_alpha_id(graph_obj, alpha_ids, set_op = "union") qd_select_nodes(graph_obj, alpha_ids, set_op = "union") select_edges_by_node_alpha_id(graph_obj, alpha_ids, set_op = "union") qd_select_edges(graph_obj, alpha_ids, set_op = "union")
graph_obj |
|
... |
Passed to |
alpha_ids |
A vector of alphanumeric node IDs upon which to operate. |
from_alpha |
A vector of alphanumeric source node IDs. |
to_alpha |
A vector of alphanumeric destination node IDs. |
set_op |
Passed to the |
Take a DAG graph object and, in the simplest case, create a single-world intervention
template corresponding to a world in which the fixed nodes are set to a given value.
Alternatively, tell qd_swig() which values fixed nodes will be set to.
qd_swig( graph_obj, fixed_nodes, custom_values = NULL, fixed_sep = getOption("quickdag.swig_fixedsep"), sep_point_size = getOption("quickdag.swig_sepsize") )qd_swig( graph_obj, fixed_nodes, custom_values = NULL, fixed_sep = getOption("quickdag.swig_fixedsep"), sep_point_size = getOption("quickdag.swig_sepsize") )
graph_obj |
A DAG object created by |
fixed_nodes |
A vector containing the nodes to be intervened upon. |
custom_values |
A named vector containing alternative labels identifying explicit
values for fixed nodes (e.g., |
fixed_sep |
A character string indicating which character to use as a separator
in fixed nodes. Defaults to |
sep_point_size |
A numerical value specifying the point size for fixed node separators. |
# Provide a DAG object and a list of nodes to be fixed edges <- c("A -> Y", "L -> { A Y }") dag <- qd_dag(edges) swig <- dag |> qd_swig(fixed_nodes = "A", custom_values = c("A" = "1")) swig |> DiagrammeR::render_graph()# Provide a DAG object and a list of nodes to be fixed edges <- c("A -> Y", "L -> { A Y }") dag <- qd_dag(edges) swig <- dag |> qd_swig(fixed_nodes = "A", custom_values = c("A" = "1")) swig |> DiagrammeR::render_graph()
Themes and theming utilies.
qd_themes(graph_obj, theme, conditioned = NULL) theme_qd_base( graph_obj, rankdir = getOption("quickdag.base_rankdir"), layout = getOption("quickdag.base_layout"), shape = getOption("quickdag.base_shape"), nodepen = getOption("quickdag.base_nodepen"), nodewidth = getOption("quickdag.base_nodewidth"), nodeheight = getOption("quickdag.base_nodeheight"), edgepen = getOption("quickdag.base_edgepen"), arrowhead = getOption("quickdag.base_arrowhead"), arrowsize = getOption("quickdag.base_arrowsize"), fontname = getOption("quickdag.base_fontname"), fontsize = getOption("quickdag.base_fontsize"), fontcolor = getOption("quickdag.base_fontcolor"), conditioned = NULL ) theme_qd_circles( graph_obj, nodepen = choose_option("quickdag.circles_nodepen"), edgepen = choose_option("quickdag.circles_edgepen"), fontname = choose_option("quickdag.circles_fontname"), fontsize = choose_option("quickdag.circles_fontsize"), fontcolor = choose_option("quickdag.circles_fontcolor"), conditioned = NULL ) theme_qd_pearl( graph_obj, pointsize = getOption("quickdag.pearl_pointsize"), pointcolor = getOption("quickdag.pearl_pointcolor"), pointfill = getOption("quickdag.pearl_pointfill"), edgepen = choose_option("quickdag.pearl_edgepen"), arrowhead = choose_option("quickdag.pearl_arrowhead"), arrowsize = choose_option("quickdag.pearl_arrowsize"), fontname = choose_option("quickdag.pearl_fontname"), fontsize = choose_option("quickdag.pearl_fontsize"), fontcolor = choose_option("quickdag.pearl_fontcolor"), conditioned = NULL ) get_conditioned_nodes(graph_obj, conditioned = NULL) cleanup_existing_theme(graph_obj)qd_themes(graph_obj, theme, conditioned = NULL) theme_qd_base( graph_obj, rankdir = getOption("quickdag.base_rankdir"), layout = getOption("quickdag.base_layout"), shape = getOption("quickdag.base_shape"), nodepen = getOption("quickdag.base_nodepen"), nodewidth = getOption("quickdag.base_nodewidth"), nodeheight = getOption("quickdag.base_nodeheight"), edgepen = getOption("quickdag.base_edgepen"), arrowhead = getOption("quickdag.base_arrowhead"), arrowsize = getOption("quickdag.base_arrowsize"), fontname = getOption("quickdag.base_fontname"), fontsize = getOption("quickdag.base_fontsize"), fontcolor = getOption("quickdag.base_fontcolor"), conditioned = NULL ) theme_qd_circles( graph_obj, nodepen = choose_option("quickdag.circles_nodepen"), edgepen = choose_option("quickdag.circles_edgepen"), fontname = choose_option("quickdag.circles_fontname"), fontsize = choose_option("quickdag.circles_fontsize"), fontcolor = choose_option("quickdag.circles_fontcolor"), conditioned = NULL ) theme_qd_pearl( graph_obj, pointsize = getOption("quickdag.pearl_pointsize"), pointcolor = getOption("quickdag.pearl_pointcolor"), pointfill = getOption("quickdag.pearl_pointfill"), edgepen = choose_option("quickdag.pearl_edgepen"), arrowhead = choose_option("quickdag.pearl_arrowhead"), arrowsize = choose_option("quickdag.pearl_arrowsize"), fontname = choose_option("quickdag.pearl_fontname"), fontsize = choose_option("quickdag.pearl_fontsize"), fontcolor = choose_option("quickdag.pearl_fontcolor"), conditioned = NULL ) get_conditioned_nodes(graph_obj, conditioned = NULL) cleanup_existing_theme(graph_obj)
graph_obj |
A DAG object created by |
theme |
A character string indicating the theme to use. Defaults to "base".
Set to |
conditioned |
A character vector indicating which nodes are conditioned upon. The shape for these nodes will be set to "rectangle". |
rankdir |
Direction of node layout. Defaults to "LR", for left-to-right. |
layout |
Layout engine. Defaults to "dot", which is the only engine explicitly used by quickdag. Other options provided by DiagrammeR::DiagrammeR may or may not work well. |
shape |
Standard node shape for a given graph. Defaults for each theme: "base" = plaintex, "circles" = circle, "pearl" = point. See Graphviz documentation for other options. |
nodepen |
Size (in points) of node outlines. By default, controlled by package options specific to each theme, each of which defaults to 0.2. |
nodewidth |
Width (in inches) of nodes. By default, controlled by package options specific to each theme. Defaults to 0. |
nodeheight |
Height (in inches) of nodes. By default, controlled by package options specific to each theme. Defaults to 0. |
edgepen |
Size (in points) of edges. By default, controlled by package options specific to each theme, each of which defaults to 0.2. |
arrowhead |
Shape of the arrowhead. See |
arrowsize |
Size of the arrowhead. See |
fontname |
Font name for text elements of the graph. By default, controlled by
package options specific to each theme, each of which defaults to "Helvetica". This
is the default in |
fontsize |
Size of text (in points). By default, controlled by package options specific to each theme, each of which defaults to 5. |
fontcolor |
Text color. By default, controlled by package options specific to each theme, each of which defaults to "black". |
pointsize |
Size of "point" shape (in points). Applies to "pearl" theme only and defaults to 0.02. |
pointcolor |
Border color for the "point" shape. Applies to "pearl" theme only and defaults to "black". |
pointfill |
Fill color for the "point" shape. Applies to "pearl" theme only and defaults to "black". |
Preview character options for use as the fixed node separator in SWIGs.
sep_opts(entity = NULL, table = FALSE)sep_opts(entity = NULL, table = FALSE)
entity |
The separator name or an HTML entity of the user's choosing. Defaults
to |
table |
Logical to show or hide HTML table display of built-in characters.
Defaults to |
By default sep_opts() returns a named vector listing the built-in separators. These
built-in HTML entities are attached to nicenames for convenience. If the user provides
the nicename for a built-in entity to the entity argument, the function will return
the appropriate HTML code. If the user provides an HTML entity that does not appear in
the built-in menu, the input will be returned verbatim. Users will typically access
this latter functionality via qd_swig().