| flow_diagram_export | R Documentation |
Renders flow_diagram() and writes it to disk. The output format is taken
from the file extension, so the same call can produce a raster image, a
vector image, or an editable office document:
flow_diagram_export(path, width = NULL, height = NULL, dpi = 300, ...)
path |
File path. The extension determines the format. |
width, height |
Plot size in inches. If NULL (default), sensible values are derived from the number of subgroups and outcomes. |
dpi |
Resolution for raster formats. Default: 300. |
... |
Further arguments passed to |
.png, .jpg/.jpeg, .tiff, .bmp - raster image.
.pdf, .svg, .eps - vector image (editable in Inkscape / Illustrator;
.svg needs the 'svglite' package).
.emf - Windows vector metafile, editable in Word once inserted
(needs the 'devEMF' package).
.docx - a Word document with the flowchart embedded as a vector
image (editable after ungrouping; needs the 'officer' package, plus
'devEMF' for the vector version, otherwise a raster image is used).
.pptx - a PowerPoint slide where every box and label is a native,
fully editable shape (needs the 'rvg' and 'officer' packages).
There is no default path: the destination must be supplied explicitly
(e.g. a file under tempdir() or a directory chosen by the user).
Invisible path, or invisible NULL if there is nothing to draw.
# Wrapped in \donttest because writing the image invokes a graphics
# device and may take more than 5 seconds; it writes only to tempdir().
if (requireNamespace("ggplot2", quietly = TRUE)) {
cb_init(id_col = "id_indiv")
df <- data.frame(
id_indiv = sprintf("ID%03d", 1:100),
g = sample(c(0L, 1L), 100, replace = TRUE),
y = sample(c(0L, 1L), 100, replace = TRUE)
)
df <- track_split(df, by = "g", value_labels = c("0" = "A", "1" = "B"))
track_outcomes(df, vars = "y", labels = list(y = "Outcome"))
# Raster (no extra packages needed); written to tempdir() and cleaned up:
out <- file.path(tempdir(), "flow.png")
flow_diagram_export(out)
unlink(out)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.