Learn R Programming

coursekata (version 0.19.0)

gf_squaresid: Add Squared Residual Visualization to a Plot

Description

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.

Usage

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

Value

A ggplot object with squared residuals added.

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.

Examples

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

Run the code above in your browser using DataLab