[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`. Automatically set to `TRUE` by [qd_embed()].
- kg
A list allowing the user to set arguments for [knitr::graphics()] (except for `path`).
Examples
dag <- qd_dag(c("L -> {A Y}", "A -> Y"))
#>
#>
#> 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> L L
#> 3 3 <NA> Y Y
#>
#> ........................ EDGE DATAFRAME ........................
#>
#> id from to rel
#> 1 1 2 1 <NA>
#> 2 2 2 3 <NA>
#> 3 3 1 3 <NA>
qd_save(dag, "dag.pdf")
# embed from code chunk using knitr::include_graphics()
qd_save(dag, "dag.pdf", embed = TRUE)
#> [1] "dag.pdf"
#> attr(,"class")
#> [1] "knit_image_paths" "knit_asis"
# `title` passed to DiagrammeR::export_graph()
qd_save(dag, "dag.pdf", title = "Demo")