Learn R Programming

valytics (version 0.3.0)

plot.ba_analysis: Plot method for ba_analysis objects

Description

Creates a Bland-Altman plot (difference vs. average) for visualizing agreement between two measurement methods. The plot displays the bias (mean difference) and limits of agreement with optional confidence intervals.

Usage

# S3 method for ba_analysis
plot(
  x,
  show_ci = TRUE,
  show_points = TRUE,
  point_alpha = 0.6,
  point_size = 2,
  line_colors = NULL,
  title = NULL,
  xlab = NULL,
  ylab = NULL,
  ...
)

# S3 method for ba_analysis autoplot( object, show_ci = TRUE, show_points = TRUE, 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 ba_analysis.

show_ci

Logical; if TRUE (default), displays confidence interval bands for bias and limits of agreement.

show_points

Logical; if TRUE (default), displays individual data points.

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 "bias", "loa", and "ci". Defaults to a clean color scheme.

title

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

xlab

Character; x-axis label. If NULL, uses "Mean of methods".

ylab

Character; y-axis label. If NULL, auto-generates based on difference type.

...

Additional arguments (currently ignored).

object

An object of class ba_analysis.

Details

The Bland-Altman plot displays:

  • Points: Each point represents a paired observation, plotted as the difference (y - x) against the average ((x + y) / 2).

  • Bias line: Solid horizontal line at the mean difference.

  • Limits of agreement: Dashed horizontal lines at bias +/- 1.96 x SD.

  • Confidence intervals: Shaded bands showing the uncertainty in the bias and LoA estimates.

Patterns to look for:

  • Funnel shape: Suggests proportional bias (variance increases with magnitude).

  • Trend: Suggests systematic relationship between difference and magnitude.

  • Outliers: Points outside the LoA may warrant investigation.

See Also

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

Examples

Run this code
# Basic Bland-Altman plot
set.seed(42)
method_a <- rnorm(50, mean = 100, sd = 15)
method_b <- method_a + rnorm(50, mean = 2, sd = 5)

ba <- ba_analysis(method_a, method_b)
plot(ba)

# Without confidence intervals
plot(ba, show_ci = FALSE)

# Customized appearance
plot(ba,
     point_alpha = 0.8,
     point_size = 3,
     title = "Method Comparison: A vs B")

# Further customization with ggplot2
library(ggplot2)
plot(ba) +
  theme_minimal() +
  scale_color_brewer(palette = "Set1")

# Using autoplot (ggplot2-style)
autoplot(ba)

Run the code above in your browser using DataLab