Portable confusion counts with reference rows and predicted columns.
Data consists of long records with class labels and a frequency, optionally
grouped into panels. Missing class labels represent omitted pairs; absent
class combinations have zero frequency. All panels use the same class order.
Compiles to HeatmapSeriesOption in src/chart/heatmap/HeatmapSeries.ts,
GridOption in src/coord/cartesian/GridModel.ts, and continuous visual maps.
to_list() emits semantic config keys; compile() emits ECharts options.
draw() fits square count cells with aligned marginal summaries to the
available canvas. Missing-pair omissions are reported in the console.
The cell counts show included observations without a separate sample-size label. Color fades and
marginal backgrounds follow the active theme unless explicitly overridden.
Usage
ConfusionConfig(
dat_path = NULL,
title = NULL,
origin = NULL,
writer = NULL,
reference = "reference",
predicted = "predicted",
count = "n",
panel = NULL,
classes = NULL,
show_metrics = TRUE,
digits = 2L,
ncol = 2L,
correct_color = "#0F6A66",
incorrect_color = "#BE2E5F",
low_color = NULL,
summary_color = NULL,
font_size = 12,
xlab = "Predicted",
ylab = "Reference"
)Arguments
- dat_path
Optional Character: Path to the data, read at draw time. The serializable alternative to passing
datatodraw().- title
Optional Character: Chart title. Declared here because it is the one property every chart type has;
paletteis not (four take acolormapinstead), and axis labels and margins are cartesian-only.- origin
Optional Named character {"user", "default", "derived"}: Where each value came from, one entry per settable property. Absent on an authored config; written by the interface that resolved it.
- writer
Optional Named character: Which interface wrote the config, as
nameandversion. Absent on an authored config.- reference
Character: Column containing reference class labels.
- predicted
Character: Column containing predicted class labels.
- count
Character: Column containing nonnegative integer frequencies.
- panel
Optional Character: Optional panel-label column; unset draws one matrix.
- classes
Optional Character vector: Ordered class labels shared by every panel; unset preserves first appearance.
- show_metrics
Logical: Show per-class rates, accuracy, and balanced accuracy.
- digits
Integer: Decimal places for rates in cells and hover text.
- ncol
Integer: Maximum number of panels per row.
- correct_color
Character: Six-digit hex color at unit fraction for correct predictions.
- incorrect_color
Character: Six-digit hex color at unit fraction for incorrect predictions.
- low_color
Optional Character: Six-digit hex color at zero row fraction; unset uses the active theme background.
- summary_color
Optional Character: Six-digit hex background for metric cells; unset uses a faint neutral tint of the active theme background.
- font_size
Numeric: Preferred cell-label font size in pixels. Constrained surfaces reduce text to fit, down to 8 pixels. Long class labels wrap and column labels rotate when needed. Increase figure dimensions if labels and metrics cannot fit without overlap.
- xlab
Character: Predicted-class axis label.
- ylab
Character: Reference-class axis label.
Statistical semantics
Color intensity is the fraction within each reference row; labels show raw counts. Sensitivity, specificity, PPV, and NPV are one-versus-rest rates for each named class. Balanced accuracy is mean class recall, including every declared class. Zero denominators produce NA, never zero; consequently balanced accuracy is NA if any declared class has no reference observations. Summaries of pooled resamples describe pooled predictions, not mean fold performance. Repeated observations are counted each time they appear.
Examples
cfg <- setup_ConfusionConfig()
draw(cfg, data = data.frame(reference = c("yes", "no"),
predicted = c("yes", "no"), n = c(8, 12)))