gf_square_resid: Add Squared Residual Visualization to a Plot

View source: R/gf_resid_gf_squaresid.R

gf_square_residR Documentation

Add Squared Residual Visualization to a Plot

Description

[Experimental]

gf_squaresid() was renamed to gf_square_resid() for naming consistency and is now deprecated.

Usage

gf_square_resid(plot, model, aspect = 4/6, alpha = 0.1, ...)

gf_squaresid(plot, model, aspect = 4/6, alpha = 0.1, ...)

Arguments

plot

A ggformula plot object, typically created with gf_point().

model

A fitted linear model object created using lm().

aspect

A numeric value controlling the square's aspect ratio. Default is 4/6.

alpha

A numeric value specifying the transparency of the square's fill. Default is 0.1.

...

Additional aesthetics passed to geom_polygon(), such as color and fill.

Details

This function adds squared residual representations to a ggformula plot, illustrating squared error as a polygon. The function dynamically adjusts the aspect ratio to ensure proper scaling of squares.

Value

A ggplot object with squared residuals added.

Examples

Height_model <- lm(Thumb ~ Height, data = Fingers)
gf_point(Thumb ~ Height, data = Fingers) %>%
  gf_model(Height_model) %>%
  gf_square_resid(Height_model, color = "blue", alpha = 0.5)

coursekata documentation built on March 11, 2026, 1:06 a.m.