View source: R/plot_sg_distribution.R
| plot_sg_distribution | R Documentation |
Bar chart of subgroups identified across simulations, filtered to
those appearing in at least min_pct of the found simulations.
Supports two column schemas (MRCT and run_simulation_analysis),
top-K capping with a pooled "Other" bar, automatic threshold
halving when no label clears the initial cut, and an n_bars
attribute for adaptive figure-height computation.
plot_sg_distribution(
results,
min_pct = 5,
title = "Distribution of Identified Subgroups",
wrap_width = 25,
any_col = "any_found",
label_col = "sg_found",
top_k = NULL,
show_other = TRUE,
min_floor_pct = 0.5,
max_halvings = 0L,
bar_label_inside = FALSE,
placeholder_on_empty = FALSE
)
results |
|
min_pct |
Numeric. Minimum percentage threshold for display
(0-100). Default: |
title |
Character. Plot title. |
wrap_width |
Integer. Character width for wrapping long
subgroup labels. Default: |
any_col |
Character. Column name of the per-replicate
detection flag. Default: |
label_col |
Character. Column name of the identified-subgroup
label string. Default: |
top_k |
Integer or |
show_other |
Logical. When |
min_floor_pct |
Numeric. Lower bound on automatic threshold
halving. Default: |
max_halvings |
Integer. Maximum number of halvings applied to
|
bar_label_inside |
Logical. Render bar labels inside bars
( |
placeholder_on_empty |
Logical. When no subgroups clear the
threshold (even after halving), return a minimal
"no data" placeholder plot with |
A ggplot2 object, or invisible(NULL) when no
subgroups are found and placeholder_on_empty = FALSE.
When a plot is returned it carries two attributes:
n_barsInteger. Number of bars in the plot
(0 in the placeholder case). Use
sgdist_fig_height() to compute an adaptive
figure height for knitr.
effective_min_pctNumeric. The threshold in effect after any automatic halving.
sgdist_fig_height for computing an adaptive
figure height from n_bars, and
run_simulation_analysis /
mrct_region_sims for the upstream simulation
engines.
## Not run:
# MRCT / mrct_region_sims() output (default column schema): one row per
# simulated trial, a 0/1 detection flag (any_found) and the label of the
# subgroup found (sg_found). A small stand-in table is built here.
sims_mrct <- data.frame(
any_found = rep(c(1L, 0L), c(40L, 10L)),
sg_found = rep(c("{z_regA <= 0}", "{z_age <= 50}", "{z_er <= 0}",
"none"), c(24L, 10L, 6L, 10L))
)
plot_sg_distribution(sims_mrct)
# run_simulation_analysis() output with top-K cap and auto-halving.
# A stand-in with its analysis, any.H and sg.def columns: 30 replicates
# each find a different subgroup, so no label reaches min_pct = 5.
results_alt <- data.frame(
analysis = "FS",
any.H = rep(c(1L, 0L), c(30L, 20L)),
sg.def = c(sprintf("{er <= %d}", 1:30), rep("", 20L))
)
fs_rows <- results_alt[results_alt$analysis == "FS", ]
p <- plot_sg_distribution(
fs_rows,
any_col = "any.H",
label_col = "sg.def",
top_k = 15L,
show_other = FALSE,
max_halvings = 2L,
bar_label_inside = TRUE,
placeholder_on_empty = TRUE,
title = "HTE: Subgroups Identified (H-hat)"
)
fig_h <- sgdist_fig_height(attr(p, "n_bars"))
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.