Draw paired observations with a fitted line, standard-error band, and an identity line. The plotting box is square and both axes share an interval. Named lists support samples of different lengths, with one fit per sample.
Usage
draw_fit(
x,
y,
group = NULL,
fit = "glm",
se = TRUE,
se_times = 1.96,
rsq = TRUE,
diagonal = TRUE,
diagonal_color = NULL,
square = TRUE,
equal_axes = TRUE,
xlab = "True",
ylab = "Predicted",
...,
legend_position = "top",
legend_placement = "outside"
)Arguments
- x
Numeric vector, single-column matrix, or list: True values.
- y
Numeric vector, single-column matrix, or list: Predicted values.
- group
Optional Atomic vector or single-column data frame: Grouping variable for multiple series.
- fit
Optional Character {"glm", "gam"}: Fit method.
NULLdisables fitting."gam"formgcv::gam(). The fitted line and standard-error band are computed per group whengroupis provided.- se
Logical: Whether to show the confidence band.
- se_times
Numeric
[0, Inf): Standard-error multiplier for the band.- rsq
Logical: Include the fitted model's R-squared in series labels. This describes the overlay fit, not predictive performance against the identity line. Constant responses have undefined R-squared, labeled
NA.- diagonal
Logical: Draw a dashed identity line within the axis limits.
- diagonal_color
Optional Character: Identity-line color.
- square
Logical: If TRUE, draw the plotting box square – equal height and width in pixels, excluding axis labels and margins.
- equal_axes
Logical: If TRUE, give one data unit the same size in pixels on both axes. Set both for a plot that is square and to scale, such as a true-versus-predicted plot whose identity line should run at 45 degrees; the two axes are then made to span the same interval. See Details.
- xlab
Optional Character: X-axis title.
- ylab
Optional Character: Y-axis title.
- ...
Additional arguments to
draw_scatter(), includingtheme,palette, limits, margins, dimensions, andfilename.- legend_position
Character {"top", "bottom", "left", "right", "top-left", "top-right", "bottom-left", "bottom-right"}: Legend anchor. Top/bottom anchors use horizontal rows; left/right anchors use a vertical column. Corner anchors align within the top or bottom row.
- legend_placement
Character {"outside", "inside"}: Relation to the plotting area. Outside placement reserves space for the complete legend; inside placement overlays the data. Neither setting adds a missing legend.
Details
The overlay uses the same implementation as draw_scatter() and
ScatterConfig. The fit is GLM or GAM; fit = NULL disables it. Missing
pairs and observations with missing groups are dropped together. Infinite
values, unequal pair lengths, and multiple response columns are rejected.
List names are matched before drawing; unnamed lists are paired by position.
Paired NULL entries in lists represent unavailable sets and are omitted.
The equivalent portable configuration is a ScatterConfig binding true,
predicted, and sample columns, with fit, se, rsq, diagonal, square,
and equal_axes set explicitly. Model objects are not needed to render it.