Learn R Programming

smatr (version 3.5-1)

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

Value

A ggplot object.

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).

Author

F. Kar, D. Falster

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.

See Also

plot.sma

Examples

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

Run the code above in your browser using DataLab