ggplot-method: Plot functions

ggplot-methodR Documentation

Plot functions

Description

This function plots a linear model fit using ggplot2. It creates a scatter plot with a regression line, and displays the regression equation along with the R² value.

Usage

## S3 method for class 'lmfit'
ggplot(data, mapping = NULL, ..., environment = parent.frame())

Arguments

data

Either a numeric vector (to be used as x) or an object containing the data (e.g., a data frame).

mapping

Either a numeric vector (to be used as y when data is numeric) or an aesthetic mapping created with ggplot2::aes(). If mapping is missing and data is a data frame, the default mapping aes(x, y) is used.

...

Other arguments passed to ggplot2 components.

environment

The environment in which to evaluate the plot. Defaults to parent.frame().

Details

When provided with two numeric vectors, the function treats them as x and y values, respectively, constructs a data frame, and applies a default mapping. Alternatively, if a data frame is provided, an aesthetic mapping (or default mapping) will be used.

Value

A ggplot object.

Examples

## Not run: 
  library(visa)
  # Using numeric vectors for x and y:
  ggplot.lmfit(1:10, 2:11)

  # Using a data frame:
  df <- data.frame(x = runif(10, 1, 10), y = runif(10, 2, 11) + 0.5)
  ggplot.lmfit(df, aes(x, y))

## End(Not run)


visa documentation built on April 4, 2025, 5:40 a.m.