gf_sd_ruler: Add a Standard Deviation Ruler to a Plot

View source: R/gf_sd_ruler.R

gf_sd_rulerR Documentation

Add a Standard Deviation Ruler to a Plot

Description

[Experimental]

Usage

gf_sd_ruler(
  p,
  y = NULL,
  data = NULL,
  x = NULL,
  where = c("middle", "mean", "median"),
  color = "red",
  size = 0.8,
  ...
)

Arguments

p

A ggplot object (typically from gf_point() or gf_jitter()).

y

The y-variable (bare name or string). Defaults to the plot's mapped y aesthetic if omitted.

data

Dataset. Defaults to p$data.

x

The x-variable for placement. Defaults to the plot's mapped x.

where

Where on the x-axis to place the ruler: "middle" (midpoint of x range), "mean", or "median".

color

Segment color. Default "red".

size

Segment linewidth. Default 0.8.

...

Additional arguments passed to ggplot2::geom_segment().

Details

Adds a vertical segment showing one standard deviation of a variable, placed at a specified x position. Works for both numeric x (scatter) and categorical x (jitter) plots.

Value

A ggplot object with the SD ruler segment added.

Examples

gf_jitter(Thumb ~ Height, data = Fingers) %>%
  gf_model(lm(Thumb ~ NULL, data = Fingers)) %>%
  gf_sd_ruler()

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