| flow_diagram | R Documentation |
Renders a publication-ready CONSORT-style diagram (a 'ggplot' object) from the information captured during the pipeline. The layout is computed automatically, so no manual positioning is needed:
flow_diagram(
title = "Eligibility flowchart",
show_exclusions = TRUE,
box_fill = "white",
border_col = "grey25",
text_size = 3.5
)
title |
Plot title. Default: "Eligibility flowchart". |
show_exclusions |
Logical. Show the side box listing the linear exclusion steps? Default: TRUE. |
box_fill |
Fill colour of the boxes. Default: "white". |
border_col |
Border colour of the boxes. Default: "grey25". |
text_size |
Base text size for the box labels. Default: 3.5. |
A vertical trunk built from the linear eligibility steps (recorded by
auto_filter() / track_step()): the cohort baseline at the top, a
single side box listing every exclusion and its count, and the eligible
cohort below.
One column of boxes per subgroup leaf of the flow tree (built with
track_split()), shown side by side under the eligible cohort.
Outcome boxes (added with track_outcomes()) stacked beneath each
subgroup column, one row per outcome, with the event count and percent.
Either part is optional: with only linear steps you get the trunk; with only a split tree you get the cohort box and its subgroup columns. The function reads the current session state and writes nothing to disk.
Requires the 'ggplot2' package (a soft dependency).
A 'ggplot' object, or invisible NULL if there is nothing to draw.
if (requireNamespace("ggplot2", quietly = TRUE)) {
cb_init(id_col = "id_indiv")
df <- data.frame(
id_indiv = sprintf("ID%04d", 1:400),
sgm = sample(c(0L, 1L), 400, replace = TRUE, prob = c(0.95, 0.05)),
self_harm = sample(c(0L, 1L), 400, replace = TRUE, prob = c(0.97, 0.03))
)
df <- track_split(df, by = "sgm", label = "SGM status",
value_labels = c("0" = "Non-SGM", "1" = "SGM"))
track_outcomes(df, vars = "self_harm",
labels = list(self_harm = "Self-harm"))
flow_diagram()
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.