Learn R Programming

valytics (version 0.3.0)

plot.deming_regression: Plot method for deming_regression objects

Description

Creates publication-ready plots for Deming regression results. Multiple plot types are available: scatter plot with regression line and residual plot.

Usage

# S3 method for deming_regression
plot(
  x,
  type = c("scatter", "residuals"),
  show_ci = TRUE,
  show_identity = TRUE,
  residual_type = c("fitted", "rank"),
  point_alpha = 0.6,
  point_size = 2,
  line_colors = NULL,
  title = NULL,
  xlab = NULL,
  ylab = NULL,
  ...
)

# S3 method for deming_regression autoplot( object, type = c("scatter", "residuals"), show_ci = TRUE, show_identity = TRUE, residual_type = c("fitted", "rank"), point_alpha = 0.6, point_size = 2, line_colors = NULL, title = NULL, xlab = NULL, ylab = NULL, ... )

Value

A ggplot object that can be further customized.

Arguments

x

An object of class deming_regression.

type

Character; type of plot to create:

  • "scatter" (default): Scatter plot with regression line, CI band, and identity line

  • "residuals": Residuals vs. fitted values or rank

show_ci

Logical; if TRUE (default), displays confidence band for the regression line (only for type = "scatter").

show_identity

Logical; if TRUE (default), displays the identity line (y = x) for reference.

residual_type

Character; for type = "residuals", plot residuals against "fitted" (default) or "rank" (ordered by x).

point_alpha

Numeric; transparency of points (0-1, default: 0.6).

point_size

Numeric; size of points (default: 2).

line_colors

Named character vector with colors for "regression", "identity", and "ci". Defaults to a clean color scheme.

title

Character; plot title. If NULL (default), generates an automatic title.

xlab, ylab

Character; axis labels. If NULL, auto-generates based on variable names.

...

Additional arguments (currently ignored).

object

An object of class deming_regression.

Details

Scatter plot (type = "scatter"): Displays the raw data with the fitted Deming regression line and optional confidence band. The identity line (y = x) is shown for reference. If the regression line overlaps substantially with the identity line, the methods are in good agreement.

Residual plot (type = "residuals"): Displays perpendicular residuals. Look for:

  • Random scatter around zero (good)

  • Patterns or trends (suggests non-linearity)

  • Funnel shape (suggests heteroscedasticity)

See Also

deming_regression() for performing the analysis, summary.deming_regression() for detailed results

Examples

Run this code
set.seed(42)
true_vals <- rnorm(50, 100, 20)
method_a <- true_vals + rnorm(50, sd = 5)
method_b <- 1.05 * true_vals + 3 + rnorm(50, sd = 5)
dm <- deming_regression(method_a, method_b)

# Scatter plot with regression line
plot(dm)

# Without identity line
plot(dm, show_identity = FALSE)

# Residual plot
plot(dm, type = "residuals")

# Residuals by rank
plot(dm, type = "residuals", residual_type = "rank")

# Customized appearance
plot(dm, point_size = 3, title = "Glucose: POC vs Reference")

Run the code above in your browser using DataLab