Constructs a ggplot2 VPC plot from a df_vpcstats() result (or any object
satisfying the vpc_stats contract). Applies the min_bin_count filter,
draws the simulated and observed quantile layers, overlays the observation
scatter, draws the LOQ reference line, applies stratification facets, and
adds the replicates caption and panel theme. The type argument selects
the continuous (concentration quantile) or censored (BLQ proportion) layer
set; the pcvpc argument selects the standard or prediction-corrected
column set within the continuous type.
Most users will reach this function indirectly via plot_vpc_cont() or
plot_vpc_cens(). Call plot_build_vpc() directly when working from a
manually-constructed or cached vpc_stats object — for example, plotting
a precomputed result from disk or a custom pipeline that produces
compatible columns.
Usage
plot_build_vpc(
compute_out,
type = c("cont", "cens"),
min_bin_count = 1,
show_rep = TRUE,
shown = NULL,
theme = NULL,
pcvpc = FALSE,
loq = NULL,
strat_var = NULL,
bin_var = BIN_MID_VAR
)Arguments
- compute_out
A
vpc_statsobject (typically the output ofdf_vpcstats()). Must containstatsandobsdata.frames with the columns documented indf_vpcstats(). Validated byvalidate_vpc_stats()at entry.- type
One of
"cont"(default) or"cens"."cont"plots the continuous concentration VPC (quantile ribbons and obs scatter)."cens"plots the BLQ-proportion VPC (proportion CI ribbon plus observed per-bin proportion line/points); requiressim_prop_blq_*columns incompute_out$stats(i.e.,df_vpcstats()was called with a LOQ source).type = "cens"is incompatible withpcvpc = TRUE.- min_bin_count
Minimum number of observations per bin required for inclusion in binned plot layers. For
type = "cont", the threshold is applied to quantifiable obs only (obs_n - obs_n_blq); BLQ-encoded records do not count toward it. Fortype = "cens", the threshold is applied to total obs (obs_n) — BLQ-heavy bins are the most informative on a cens VPC and are retained.- show_rep
Logical. Display replicate count as a plot caption.
- shown
Layer visibility settings created by
plot_vpc_shown(). Fortype = "cens", only theobs_point,obs_median_line,sim_median_line, andsim_median_cikeys are read. Defaults followplot_vpc_shown(): observed proportion line/points and simulated CI ribbon are shown; the simulated median line is off by default (passplot_vpc_shown(sim_median_line = TRUE)to enable it).- theme
Aesthetic parameters created by
plot_vpc_theme(). Fortype = "cens", only the keys corresponding to the four cens layers above are read; other keys are ignored. The censobs_pointcolor is inherited fromobs_median_line(so points match the obs line); theobs_pointtheme key still controls shape/alpha/size.- pcvpc
Logical. When
TRUE, plot the prediction-corrected columns (pc_*for stats,PC_OBSDVfor the obs scatter) and suppress the LOQ reference line. Default isFALSE(standard VPC). Only meaningful whentype = "cont".- loq
Numeric scalar or vector of LOQ values for the reference line, or
NULLto suppress. When omitted (inherited fromcompute_out$config$loq) andstrat_varis set andcompute_out$obscarries a row-alignedLOQcolumn, ref lines are drawn per facet — each facet shows only the LLOQ values applicable to its strat-level rows. Whenloqis supplied explicitly, the value always wins and one global reference line is drawn per unique value ofloq(the per-facet column-based dispatch is reserved for the inherited case). In the no-stratification or no-obs$LOQcases, a global reference line is drawn per unique value ofloqregardless of inheritance. The legend entry for LLOQ is not attached here — pass the same value toplot_vpc_legend()when composing the legend panel.compute_out$config$loqis already a vector of unique non-NA LOQ values whendf_vpcstats()populated the container. Forced toNULLwhenpcvpc = TRUE(LOQ has no meaning on the prediction-corrected scale).- strat_var
Stratification variable. Accepts bare names or strings. Default is
NULL. WhenNULL, the value is read fromcompute_out$config$strat_varso output ofdf_vpcstats()is handled automatically.- bin_var
String. Binning variable name. Default is
"BIN_MID".
Examples
model <- model_mread_load(model = "pkmodel")
#> Loading model from cache.
simout <- df_mrgsim_replicate(data = data_sad, model = model, replicates = 5,
dv_var = ODV, carry_out = "FOOD")
out <- df_vpcstats(simout, strat_var = FOOD)
#> Warning: Multiple unique values of `CMT` detected in `data` after filtering to `EVID == 0`: 2, 3.
#> ℹ Functions assume a single observation type per call.
#> ℹ Pre-filter to a single observation compartment (e.g., `dplyr::filter(data, CMT == <n>)`) before passing to this function.
p <- plot_build_vpc(out, pcvpc = FALSE)
