Learn R Programming

visa (version 1.0.0)

ggplot-method: 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 lmfit
ggplot(data, mapping = NULL, ..., environment = parent.frame())

Value

A ggplot object.

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.

Examples

Run this code
if (FALSE) {
  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))
}

Run the code above in your browser using DataLab