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().
Arguments
- graph
A graph object produced by
qd_dag()- 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
DiagrammeR::export_graph()for details.- ...
Pass other arguments to
DiagrammeR::render_graph().- embed
Defaults to
FALSE.- kg
A list allowing the user to set arguments for
knitr::include_graphics()(except forpath).
Examples
# 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)
#> [1] "/tmp/RtmpnnzWF3/dag.pdf"
#> attr(,"class")
#> [1] "knit_image_paths" "knit_asis"
# `title` passed to DiagrammeR::export_graph()
qd_save(dag, file, title = "Demo")
# clean up temporary directory
file.remove(file)
#> [1] TRUE