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",
legend_title = NULL
)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. Series, colors, and legend entries follow factor level order, or first appearance for other vectors.
- fit
Optional Character: Model fitted to
yonxand drawn as a line."glm"usesstats::glm()and"gam"usesmgcv::gam(). Any other name, matched case-insensitively, is an rtemis supervised learning algorithm, such as"LINAD","CART"or"LightGBM", trained with its default hyperparameters; this requires the rtemis package (>= 1.4.1).NULLdisables fitting. The fitted line and standard-error band are computed per group whengroupis provided.- se
Logical: Whether to show the standard-error band. Algorithms without standard errors (every rtemis algorithm except GLM, GAM and a few others) draw the line alone.
- 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.
- legend_title
Optional Character: Title drawn with the legend or colorbar: above left/right legends and vertical colorbars, before the first row of top/bottom legends and horizontal colorbars.
NULLdraws no title. A title does not add a missing legend.
Details
The overlay uses the same implementation as draw_scatter() and
ScatterConfig. The fit is GLM, GAM, or an rtemis learner named in fit;
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.