Learn R Programming

loa (version 0.3.1.1)

5.3.plot.add.XYFit.functions: Plot add.XY...Fit functions

Description

Functions for adding XY fit model layers to existing plots.

Usage

#main functions

add.loaPanel(lattice.plot = NULL, preprocess = NULL, panel = NULL, postprocess = NULL, ..., use = NULL, ignore = NULL)

add.XYLMFit(lattice.plot = NULL, preprocess = add.XYFit_prep, panel = panel.loaXYFit, ...)

add.XYLOESSFit(lattice.plot = NULL, preprocess = add.XYFit_prep, model.method = loaXYFit_loess, panel = panel.loaXYFit, ...)

#others

add.XYFit_prep(lattice.plot = NULL, model.method = loaXYFit_lm, ...)

loaXYFit_lm(x, y, output.len = 25, formula.signif = 2, r2.digits = 3, group.id = NULL, ...)

loaXYFit_loess(x, y, output.len = 25, r2.digits = 3, group.id = NULL, ...)

panel.loaXYFit(...)

Value

add.XYLMFit returns the supply (or last) lattice plot with an added linear fit surface layer, generated using

lm().

add.XYLMFit returns the supply (or last) lattice plot with an added linear fit surface layer, generated using

loess().

The elements of the XYFit layers are fit the fit line,

se the standard error bands, and report the fit report panels. These track properties, e.g. col, etc, of the plot they add to unless these terms are reset in the addXYFit call. They can also be removed by setting to FALSE, e.g. fit=FALSE, or updated individually using e.g.

fit.col=2 to change just the fit line color to red.

The report position within the plot panel can be set using report.position which uses a relative (x=0-1, y=0-1) scale to position the report.

Arguments

lattice.plot

The plot to add an extra layer or layers to. This defaults to last lattice plot produced if not set in call.

preprocess

If set, a function to apply to lattice.plot before adding new panel.

panel

If set, a new panel... function to add to lattice.plot after the current lattice.plot panel.

postprocess

If set, a function to apply to lattice.plot after the new panel.

...

Additional arguments, passed on to daughter functions.

model.method

Function to use on XY data to generate fit reports.

use,ignore

if set, the names of arguments supplied to the previous plot that should be used or ignored, respectively, by panel being added.

x, y

XY data from plot, typically filtered by both panel and group.

output.len

Number of XY pairs to use when making fit line standard error bands.

formula.signif, r2.digits

When number of significant numbers and digits to use when reporting the fit formula and r.squared, respectively.

group.id

When XY data is grouped, the group identity.

Author

Karl Ropkins

Details

add.loaPanel adds a plot panel to an existing loaPlot output.

add.XYLMFit and add.XYLFit add linear and loess model fit surfaces to exiting lattice plot.

Both functions are intended to be used in form:

[make plot, e.g. loaPlot(...) then] addXYLMFit(...)

loaXYFit_lm and loaXYFit_lm generate fit and report information for linear and loess fit surfaces.

Other functions contain code structure common to all addXYFit functions.

References

This function makes extensive use of code developed by others.

lattice: Sarkar, Deepayan (2008) Lattice: Multivariate Data Visualization with R. Springer, New York. ISBN 978-0-387-75968-5

lm() and loess() in stats (part of base R): R Core Team (2017). R: A language and environment for statistical computing. R Foundation for Statistical Computing, Vienna, Austria. URL https://www.R-project.org/.

Examples

Run this code

# add lm fit a loaPlot
add.XYLMFit(loaPlot(cadmium~copper*zinc, data=lat.lon.meuse))

if (FALSE) {

loaPlot(cadmium~copper*zinc, data=lat.lon.meuse)
add.XYLOESSFit(col="red")

p <- loaPlot(cadmium~copper*zinc, data=lat.lon.meuse)
add.XYLMFit(p, se.col="grey", report.position=c(0.95, 0.22))

}

Run the code above in your browser using DataLab