ggplot.sma: Plot a (S)MA fit using ggplot2

View source: R/ggplot.sma.R

ggplot.smaR Documentation

Plot a (S)MA fit using ggplot2

Description

Produce a ggplot2 version of the default x-y plot for an sma fit: the data points plus the fitted (standardised) major axis line(s), with separate colours for each group where present. This is a ggplot2-based alternative to the base-graphics plot.sma.

Usage

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

Arguments

data

An object of class sma, as returned by sma or ma. (Named data for consistency with the ggplot2::ggplot generic.)

mapping, environment

Present for consistency with the ggplot2::ggplot generic; not used.

...

Further arguments passed to geom_line for the fitted lines (for example linewidth or linetype).

Details

Data and fitted lines are drawn on the natural (back-transformed) scale of the original variables. Where the fit used a log transformation (log was one of "x", "y" or "xy"), the corresponding axis is drawn on a log10 scale via scale_x_log10 / scale_y_log10. The fitted line geometry mirrors the curve logic used by plot.sma, so both plotting methods agree.

The returned object is a standard ggplot object and can be further customised with additional layers, themes, scales and facets in the usual way.

Value

A ggplot object.

Author(s)

F. Kar, D. Falster

See Also

plot.sma

Examples

## Not run: 
data(leaflife)
leaf.low.soilp <- subset(leaflife, soilp == "low")

# Single fit
ft1 <- sma(longev ~ lma, data = leaf.low.soilp, log = "xy")
ggplot2::ggplot(ft1)

# Grouped fit with common-slope test
ft2 <- sma(longev ~ lma * rain, data = leaf.low.soilp, log = "xy")
ggplot2::ggplot(ft2)

# ggplot object can be extended as usual
ggplot2::ggplot(ft2) + ggplot2::theme_minimal()

## End(Not run)

smatr documentation built on Oct. 7, 2026, 1:08 a.m.