Title: | New and Extended Plots, Methods, and Panel Functions for 'lattice' |
---|---|
Description: | Extensions to 'lattice', providing new high-level functions, methods for existing functions, panel functions, and a theme. |
Authors: | Johan Larsson [aut, cre] , Deepayan Sarkar [ctb, cph] (lattice), Brian Ripley [ctb] (stats::plot.acf) |
Maintainer: | Johan Larsson <[email protected]> |
License: | GPL-3 |
Version: | 0.2.1 |
Built: | 2024-10-29 04:01:47 UTC |
Source: | https://github.com/jolars/tactile |
Draws bubbleblots – trivariate plots where the third dimension is mapped to the size of the points drawn on the screen.
bubbleplot(x, data = NULL, ...) ## S3 method for class 'formula' bubbleplot( x, data = NULL, maxsize = 3, bubblekey = TRUE, panel = panel.bubbleplot, groups = NULL, subset = TRUE, drop.unused.levels = lattice.getOption("drop.unused.levels"), ..., outer, allow.multiple )
bubbleplot(x, data = NULL, ...) ## S3 method for class 'formula' bubbleplot( x, data = NULL, maxsize = 3, bubblekey = TRUE, panel = panel.bubbleplot, groups = NULL, subset = TRUE, drop.unused.levels = lattice.getOption("drop.unused.levels"), ..., outer, allow.multiple )
x |
A formula of the form |
data |
A data.frame, list or environment wherein the formula and groups arguments can be evaluated. |
... |
Further arguments to pass to |
maxsize |
Maximum size (in cex) for the bubbles. |
bubblekey |
Set to |
panel |
See |
groups |
|
subset |
|
drop.unused.levels |
|
outer |
Ignored. |
allow.multiple |
Ignored. |
An object of class "trellis"
. The
update
method can be used to
update components of the object and the
print
method (usually called by
default) will plot it on an appropriate plotting device.
Johan Larsson
bubbleplot(disp ~ hp * wt, groups = cyl, data = mtcars, auto.key = TRUE) bubbleplot(disp ~ hp * mpg | factor(cyl), groups = gear, data = mtcars, auto.key = TRUE)
bubbleplot(disp ~ hp * wt, groups = cyl, data = mtcars, auto.key = TRUE) bubbleplot(disp ~ hp * mpg | factor(cyl), groups = gear, data = mtcars, auto.key = TRUE)
An extended version of lattice::bwplot()
. The only modification is to
group and stack box plots if groups
is provided.
bwplot2(x, data = NULL, ...) ## S3 method for class 'formula' bwplot2( x, data = NULL, allow.multiple = is.null(groups) || outer, outer = FALSE, auto.key = FALSE, groups = NULL, drop.unused.levels = lattice.getOption("drop.unused.levels"), ..., subset = TRUE ) ## S3 method for class 'numeric' bwplot2(x, data = NULL, xlab = deparse(substitute(x)), ...)
bwplot2(x, data = NULL, ...) ## S3 method for class 'formula' bwplot2( x, data = NULL, allow.multiple = is.null(groups) || outer, outer = FALSE, auto.key = FALSE, groups = NULL, drop.unused.levels = lattice.getOption("drop.unused.levels"), ..., subset = TRUE ) ## S3 method for class 'numeric' bwplot2(x, data = NULL, xlab = deparse(substitute(x)), ...)
x |
|
data |
|
... |
arguments passed down to |
allow.multiple |
|
outer |
|
auto.key |
|
groups |
|
drop.unused.levels |
|
subset |
|
xlab |
An object of class "trellis"
. The
update
method can be used to
update components of the object and the
print
method (usually called by
default) will plot it on an appropriate plotting device.
bwplot2(variety ~ yield, groups = site, data = barley, par.settings = tactile.theme())
bwplot2(variety ~ yield, groups = site, data = barley, par.settings = tactile.theme())
Plots univariate density estimates estimates to be used in a
lattice::splom()
call with the diag.panel
argument.
diag.panel.splom.density( x, bw = "nrd0", adjust = 1, kernel = "gaussian", weights = NULL, n = 512, ... )
diag.panel.splom.density( x, bw = "nrd0", adjust = 1, kernel = "gaussian", weights = NULL, n = 512, ... )
x |
data vector corresponding to that row / column (which will be the same for diagonal 'panels'). |
bw |
the smoothing bandwidth to be used. The kernels are scaled such that this is the standard deviation of the smoothing kernel. (Note this differs from the reference books cited below, and from S-PLUS.)
The specified (or computed) value of |
adjust |
the bandwidth used is actually |
kernel |
the smoothing kernel to be used. See |
weights |
numeric vector of non-negative observation weights,
hence of same length as Note that weights are not taken into account for automatic
bandwidth rules, i.e., when |
n |
the number of equally spaced points at which the density is
to be estimated. When |
... |
Further arguments passed on to |
lattice::diag.panel.splom()
, lattice::splom()
,
stats::density()
.
splom(~ iris[1:4], data = iris, diag.panel = diag.panel.splom.density, pscales = 0 )
splom(~ iris[1:4], data = iris, diag.panel = diag.panel.splom.density, pscales = 0 )
A data set that has been manually transcribed from Table 5 of Elkins and Grove's Ternary feldspar experiments and thermodynamic models.
feldspar
feldspar
A data frame of 40 rows and 7 columns:
The ID of the experiment
Coexisting feldspars, Alkali or Plagioclase
Proportion of orthoclase
Proportion of anorthite
Proportion of albite
Temperature of the reaction (degrees centigrade)
Pressure of the reaction (bars)
This paper reports the results of 20 experiments in which mixes of two or three feldspars were reacted to produce coexisting plagioclase feldspar (PF) and alkali feldspar (AF). Starting materials with similar bulk compositions were prepared using different combinations of two and three minerals, and experiments were designed to produce similar AF and PF minerals in the experimental products from different starting binary and ternary compositions. The coexisting AF and PF compositions produced as products define compositional fields that are elongate parallel to the ternary solvus. In 11 experiments reaction was sufficient to product fields of coexisting AF and PF, or AF, PF, and melt with a bulk composition close to that of the starting mixture. In six experiments significant reaction occurred in the form of reaction rim overgrowths on seeds of the starting materials. Three experiments produced AF, PF, and melt from a natural granite starting material. A two-feldspar thermometer is presented in which temperature is constrained by equilibria among all three components - Albite, Orthoclase, and Anorthite - in coexisting ternary feldspars.
Elkins LT, Grove TL. Ternary feldspar experiments and thermodynamic models. American Mineralogist. 1990;75(5-6):544-59.
Panel Function for Bubble Plots
panel.bubbleplot(x, y, z, groups = NULL, subscripts, cex = NULL, ...)
panel.bubbleplot(x, y, z, groups = NULL, subscripts, cex = NULL, ...)
x , y
|
variables to be plotted in the scatterplot |
z |
A numeric vector that areas of circles will be mapped to. |
groups |
Grouping variable (see |
subscripts |
A vector of indexes to specify which observation to plot. Normally does not need to be provided by the user. |
cex |
Is used internally and user settings will be ignored. |
... |
Further arguments to pass to |
Plots a layer inside a panel of a lattice
plot.
Panel function for confidence interval
panel.ci( x, y, lower, upper, groups = NULL, subscripts, col, fill = if (is.null(groups)) plot.line$col else superpose.line$col, alpha = 0.15, lty = 0, lwd = if (is.null(groups)) plot.line$lwd else superpose.line$lwd, grid = FALSE, ..., col.line = if (is.null(groups)) plot.line$col else superpose.line$col )
panel.ci( x, y, lower, upper, groups = NULL, subscripts, col, fill = if (is.null(groups)) plot.line$col else superpose.line$col, alpha = 0.15, lty = 0, lwd = if (is.null(groups)) plot.line$lwd else superpose.line$lwd, grid = FALSE, ..., col.line = if (is.null(groups)) plot.line$col else superpose.line$col )
x , y
|
variables to be plotted in the scatterplot |
lower |
lower confidence limits |
upper |
upper confidence limits |
groups |
an optional grouping variable. If present,
|
subscripts |
|
col |
line color |
fill |
fill color |
alpha |
opacity for the fill |
lty |
line type |
lwd |
line width |
grid |
A logical flag, character string, or list specifying whether and how
a background grid should be drawn. This provides the same
functionality as Most generally,
No grid is drawn if |
... |
Extra arguments, if any, for |
col.line |
line color. Supersedes |
mod <- lm(Petal.Width ~ Petal.Length * Species, data = iris) newdat <- expand.grid( Petal.Length = seq(1, 7, by = 0.1), Species = c("setosa", "versicolor", "virginica") ) pred <- predict(mod, newdat, interval = "confidence") dd <- cbind(newdat, pred) xyplot( fit ~ Petal.Length, groups = Species, data = dd, prepanel = prepanel.ci, auto.key = list(lines = TRUE, points = FALSE), ylab = "Petal Width", xlab = "Petal Length", lower = dd$lwr, upper = dd$upr, type = "l", panel = function(...) { panel.ci(..., alpha = 0.15, grid = TRUE) panel.xyplot(...) } )
mod <- lm(Petal.Width ~ Petal.Length * Species, data = iris) newdat <- expand.grid( Petal.Length = seq(1, 7, by = 0.1), Species = c("setosa", "versicolor", "virginica") ) pred <- predict(mod, newdat, interval = "confidence") dd <- cbind(newdat, pred) xyplot( fit ~ Petal.Length, groups = Species, data = dd, prepanel = prepanel.ci, auto.key = list(lines = TRUE, points = FALSE), ylab = "Petal Width", xlab = "Petal Length", lower = dd$lwr, upper = dd$upr, type = "l", panel = function(...) { panel.ci(..., alpha = 0.15, grid = TRUE) panel.xyplot(...) } )
Panel function to go along with lattice::qqmath()
and
lattice::panel.qqmathline()
. Adds filled confidence bands to the Q-Q-plot.
panel.qqmathci( x, y = x, distribution = qnorm, probs = c(0.25, 0.75), qtype = 7, groups = NULL, ci = 0.95, alpha = 0.25, col = trellis.par.get("plot.line")$col, ..., col.line )
panel.qqmathci( x, y = x, distribution = qnorm, probs = c(0.25, 0.75), qtype = 7, groups = NULL, ci = 0.95, alpha = 0.25, col = trellis.par.get("plot.line")$col, ..., col.line )
x |
The original sample, possibly reduced to a fewer number of
quantiles, as determined by the |
y |
an alias for |
distribution |
quantile function for reference theoretical distribution. |
probs |
numeric vector of length two, representing probabilities. Corresponding quantile pairs define the line drawn. |
qtype |
the |
groups |
optional grouping variable. If non-null, a line will be drawn for each group. |
ci |
Confidence level |
alpha |
Alpha level for the color fill |
col |
Color fill for the confidence bands. |
... |
Arguments passed to |
col.line |
Color fill for the confidence bands. Is used internally
by |
The function tries to figure out the density function counterpart to
that provided in the argument distribution
by regular expressions.
Augments a trellis plot panel, such as that
created by lattice::qqmath()
, with confidence levels.
Johan Larsson.
lattice::panel.qqmathline()
, lattice::qqmath()
, and
lattice::panel.qqmath()
.
qqmath(~ height | voice.part, aspect = "xy", data = singer, prepanel = prepanel.qqmathline, panel = function(x, ...) { panel.qqmathci(x, ...) panel.qqmathline(x, ...) panel.qqmath(x, ...) })
qqmath(~ height | voice.part, aspect = "xy", data = singer, prepanel = prepanel.qqmathline, panel = function(x, ...) { panel.qqmathci(x, ...) panel.qqmathline(x, ...) panel.qqmath(x, ...) })
Panel Function for Ternary Plots
panel.ternaryplot( x, y, z, subscripts, response = NULL, density = FALSE, region = density || !is.null(response), contour = density || !is.null(response), labels = !is.null(response), points = TRUE, grid = TRUE, density_breaks = NULL, xlab, ylab, zlab, xlab.default, ylab.default, zlab.default, ... )
panel.ternaryplot( x, y, z, subscripts, response = NULL, density = FALSE, region = density || !is.null(response), contour = density || !is.null(response), labels = !is.null(response), points = TRUE, grid = TRUE, density_breaks = NULL, xlab, ylab, zlab, xlab.default, ylab.default, zlab.default, ... )
x |
Numeric vector |
y |
Numeric vector |
z |
Numeric vector |
subscripts |
|
response |
An optional response variable |
density |
Compute two-dimensional density estimates via |
region |
Fill density or response estimates with a color gradient. |
contour |
Draw contour lines for density and response estimates. |
labels |
Label contour lines. |
points |
Draw points (via |
grid |
Draw a reference grid. |
density_breaks |
Breaks for the density plot if used (see
|
xlab |
X axis label (the left dimension) |
ylab |
Y axis label (the right dimension) |
zlab |
Z axis label (the top dimension) |
xlab.default |
Internal argument |
ylab.default |
Internal argument |
zlab.default |
Internal argument |
... |
Arguments passed down to subsequent panel functions. |
Plots a layer inside a panel of a lattice
plot.
The building blocks of this function are available as the separate
panel functions panel.ternaryplot.xyplot()
, panel.ternaryplot.grid()
,
panel.ternaryplot.scales()
, panel.ternaryplot.clip()
,
panel.ternaryplot.response()
, and panel.ternaryplot.density()
in case
the user would like to get complete control of the customization.
Plot Region Clipping for Ternary Plots
panel.ternaryplot.clip( xl = current.panel.limits()$x, yl = current.panel.limits()$y, border = "transparent", col = if (background$col == "transparent") "#FFFFFF" else background$col )
panel.ternaryplot.clip( xl = current.panel.limits()$x, yl = current.panel.limits()$y, border = "transparent", col = if (background$col == "transparent") "#FFFFFF" else background$col )
xl |
X axis limits |
yl |
Y axis limits |
border |
Border color |
col |
Polygon fill |
Plots a layer inside a panel of a lattice
plot.
Two-Dimensional Density Estimation for Ternary Plots
panel.ternaryplot.density( x, y, z, subscripts, n = 100, region = TRUE, contour = FALSE, labels = isTRUE(contour), density_breaks = NULL, ... )
panel.ternaryplot.density( x, y, z, subscripts, n = 100, region = TRUE, contour = FALSE, labels = isTRUE(contour), density_breaks = NULL, ... )
x |
Numeric vector |
y |
Numeric vector |
z |
Numeric vector |
subscripts |
|
n |
Number of grid points in each direction. Can be scalar or a length-2 integer vector. |
region |
Fill density or response estimates with a color gradient. |
contour |
Draw contour lines for density and response estimates. |
labels |
Label contour lines. |
density_breaks |
Breaks for the density plot if used (see
|
... |
Arguments that will be passed on to |
Plots a layer inside a panel of a lattice
plot.
Reference Grid for Ternary Plot
panel.ternaryplot.grid( at = seq.int(0, 1, by = 0.2), alpha = reference.line$alpha, col = reference.line$col, lty = reference.line$lty, lwd = reference.line$lwd )
panel.ternaryplot.grid( at = seq.int(0, 1, by = 0.2), alpha = reference.line$alpha, col = reference.line$col, lty = reference.line$lty, lwd = reference.line$lwd )
at |
Where to draw the reference lines |
alpha |
Alpha |
col |
Color |
lty |
Line type |
lwd |
Line weight |
Plots a layer inside a panel of a lattice
plot.
Response Panels for Ternary Plots
panel.ternaryplot.response( x, y, z, subscripts, response, region = TRUE, contour = TRUE, labels = isTRUE(contour), fun = c("glm", "lm"), formula = response ~ poly(x, y), ... )
panel.ternaryplot.response( x, y, z, subscripts, response, region = TRUE, contour = TRUE, labels = isTRUE(contour), fun = c("glm", "lm"), formula = response ~ poly(x, y), ... )
x |
Numeric vector |
y |
Numeric vector |
z |
Numeric vector |
subscripts |
|
response |
An optional response variable |
region |
Fill density or response estimates with a color gradient. |
contour |
Draw contour lines for density and response estimates. |
labels |
Label contour lines. |
fun |
Function to apply to the response variable. |
formula |
Formula for the function. |
... |
Arguments passed on to |
Plots a layer inside a panel of a lattice
plot.
Axes and Labels for Ternary Plots
panel.ternaryplot.scales( xlab, ylab, zlab, xlab.default, ylab.default, zlab.default, at = seq.int(0, 1, by = 0.2), ... )
panel.ternaryplot.scales( xlab, ylab, zlab, xlab.default, ylab.default, zlab.default, at = seq.int(0, 1, by = 0.2), ... )
xlab , ylab , zlab
|
Labels, have to be lists. Typically the user will not manipulate
these, but instead control this via arguments to |
xlab.default |
for internal use |
ylab.default |
for internal use |
zlab.default |
for internal use |
at |
Where to draw tick marks. |
... |
Currently ignored. |
Plots a layer inside a panel of a lattice
plot.
This mainly exists to enable users to string together their own ternary plot functions.
panel.ternaryplot.xyplot(x, y, z, subscripts, ...)
panel.ternaryplot.xyplot(x, y, z, subscripts, ...)
x |
Numeric vector of values in the original space |
y |
Numeric vector of values in the original space |
z |
Numeric vector of values in the original space |
subscripts |
see |
... |
Arguments that are passed on to |
Plots a layer inside a panel of a lattice
plot.
Prepanel for ciplot
prepanel.ci(x, y, lower, upper, subscripts, groups = NULL, ...)
prepanel.ci(x, y, lower, upper, subscripts, groups = NULL, ...)
x , y
|
x and y values, numeric or factor |
lower |
lower confidence limits |
upper |
upper confidence limits |
groups , subscripts
|
See |
... |
other arguments, usually ignored |
mod <- lm(Petal.Width ~ Petal.Length * Species, data = iris) newdat <- expand.grid( Petal.Length = seq(1, 7, by = 0.1), Species = c("setosa", "versicolor", "virginica") ) pred <- predict(mod, newdat, interval = "confidence") dd <- cbind(newdat, pred) xyplot( fit ~ Petal.Length, groups = Species, data = dd, prepanel = prepanel.ci, ylab = "Petal Width", xlab = "Petal Length", lower = dd$lwr, upper = dd$upr, alpha = 0.3, panel = function(...) { panel.ci(..., grid = TRUE) panel.xyplot(type = "l", ...) } )
mod <- lm(Petal.Width ~ Petal.Length * Species, data = iris) newdat <- expand.grid( Petal.Length = seq(1, 7, by = 0.1), Species = c("setosa", "versicolor", "virginica") ) pred <- predict(mod, newdat, interval = "confidence") dd <- cbind(newdat, pred) xyplot( fit ~ Petal.Length, groups = Species, data = dd, prepanel = prepanel.ci, ylab = "Petal Width", xlab = "Petal Length", lower = dd$lwr, upper = dd$upr, alpha = 0.3, panel = function(...) { panel.ci(..., grid = TRUE) panel.xyplot(type = "l", ...) } )
Draw quantile-Quantile plots of a sample against a theoretical distribution, possibly conditioned on other variables.
## S3 method for class 'zoo' qqmath( x, data = NULL, xlab = "Theoretical quantiles", ylab = "Sample quantiles", ref = TRUE, ci = TRUE, ... )
## S3 method for class 'zoo' qqmath( x, data = NULL, xlab = "Theoretical quantiles", ylab = "Sample quantiles", ref = TRUE, ci = TRUE, ... )
x |
A |
data |
Ignored |
xlab |
X axis label |
ylab |
Y axis label |
ref |
Plot a reference line via |
ci |
Plot confidence levels via |
... |
Parameters to pass on to |
Plots and returns a trellis
object.
Original by Deepayan Sarkar.
lattice::qqmath()
, zoo::zoo()
, lattice::panel.qqmathline()
.
if (require(zoo)) qqmath(zoo(lh))
if (require(zoo)) qqmath(zoo(lh))
A custom theme for lattice that tries to make away with some of the
(in this author's opinion) excessive margins that result from the default
settings. It also provides a different color theme based partly on
latticeExtra::custom.theme()
.
tactile.theme(fontsize = c(12, 8), color = TRUE, ...)
tactile.theme(fontsize = c(12, 8), color = TRUE, ...)
fontsize |
A vector of two numeric scalars for text and symbols respectively. |
color |
Colorized theme. |
... |
Additional named options. |
The theme currently modifies the default lattice theme so that
paddings (margins) are minimized,
axis tick lengths are halved, and
title size is decreased slightly.
A list of graphical parameters that for instance could be supplied
inside a call to lattice::xyplot()
or set via
lattice::lattice.options()
.
xyplot(speed ~ dist, data = cars, par.settings = tactile.theme()) opars <- trellis.par.get() trellis.par.set(tactile.theme()) show.settings() trellis.par.set(opars)
xyplot(speed ~ dist, data = cars, par.settings = tactile.theme()) opars <- trellis.par.get() trellis.par.set(tactile.theme()) show.settings() trellis.par.set(opars)
A ternary plot is a triangular diagram that displays proportions of three variables. It can be used to map three-dimensional data to a two-dimensional surface with the caveat that the data's original scales are lost (unless it was proportional data to begin with).#'
ternaryplot(x, data, ...) ## S3 method for class 'formula' ternaryplot( x, data = NULL, response = NULL, groups = NULL, density = FALSE, region = density || !is.null(response), contour = density || !is.null(response), labels = !is.null(response), colorkey = region, xlab, ylab, zlab, xlim = c(-0.15, 1.15), ylim = c(-0.3, 1), panel = panel.ternaryplot, default.prepanel = lattice.getOption("prepanel.default.xyplot"), drop.unused.levels = lattice.getOption("drop.unused.levels"), subset = TRUE, ... ) ## S3 method for class 'data.frame' ternaryplot(x, data = NULL, ...) ## S3 method for class 'matrix' ternaryplot(x, data = NULL, ...)
ternaryplot(x, data, ...) ## S3 method for class 'formula' ternaryplot( x, data = NULL, response = NULL, groups = NULL, density = FALSE, region = density || !is.null(response), contour = density || !is.null(response), labels = !is.null(response), colorkey = region, xlab, ylab, zlab, xlim = c(-0.15, 1.15), ylim = c(-0.3, 1), panel = panel.ternaryplot, default.prepanel = lattice.getOption("prepanel.default.xyplot"), drop.unused.levels = lattice.getOption("drop.unused.levels"), subset = TRUE, ... ) ## S3 method for class 'data.frame' ternaryplot(x, data = NULL, ...) ## S3 method for class 'matrix' ternaryplot(x, data = NULL, ...)
x |
See Methods (by class). |
data |
A data frame in which the |
... |
Arguments that are passed on to other methods, particularly
|
response |
An optional response variable |
groups |
A variable or expression to be evaluated in |
density |
Compute two-dimensional density estimates via |
region |
Fill density or response estimates with a color gradient. |
contour |
Draw contour lines for density and response estimates. |
labels |
Label contour lines. |
colorkey |
if |
xlab |
X axis label (the left dimension) |
ylab |
Y axis label (the right dimension) |
zlab |
Z axis label (the top dimension) |
xlim |
X limits for the plot region. |
ylim |
Y limits for the plot region. |
panel |
The panel function. |
default.prepanel |
The default prepanel function. |
drop.unused.levels |
Drop unused conditioning or groups levels. |
subset |
An expression that evaluates to a logical or integer indexing vector. Like groups, it is evaluated in data. Only the resulting rows of data are used for the plot. |
An object of class "trellis"
. The
update
method can be used to
update components of the object and the
print
method (usually called by
default) will plot it on an appropriate plotting device.
ternaryplot(formula)
: A formula of the form top ~ left * right
. Variables
will be evaluated inside data if provided.
ternaryplot(data.frame)
: A data frame for which the first three columns will
be mapped to the left, right, and top dimensions of the ternary plot
respectively.
ternaryplot(matrix)
: A matrix for which the
first three columns will be mapped to the left, right, and top
dimensions of the ternary plot respectively.
ternaryplot(Fertility ~ Agriculture * Catholic, data = swiss) ternaryplot(Catholic ~ Examination * Education, response = Infant.Mortality, data = swiss, contour = FALSE) ternaryplot(Or ~ An * Ab | Feldspar, data = feldspar) ternaryplot(Or ~ An * Ab, groups = Feldspar, data = feldspar, density = TRUE)
ternaryplot(Fertility ~ Agriculture * Catholic, data = swiss) ternaryplot(Catholic ~ Examination * Education, response = Infant.Mortality, data = swiss, contour = FALSE) ternaryplot(Or ~ An * Ab | Feldspar, data = feldspar) ternaryplot(Or ~ An * Ab, groups = Feldspar, data = feldspar, density = TRUE)
This is a version of stats::plot.acf()
.
## S3 method for class 'acf' xyplot( x, data = NULL, ci = 0.95, ci_type = c("white", "ma"), ci_col = trellis.par.get("add.line")$col, ci_lty = 2, ... )
## S3 method for class 'acf' xyplot( x, data = NULL, ci = 0.95, ci_type = c("white", "ma"), ci_col = trellis.par.get("add.line")$col, ci_lty = 2, ... )
x |
An 'acf' object. |
data |
Ignored |
ci |
Confidence level. |
ci_type |
Type of confidence level. |
ci_col |
Line color for the confidence levels. |
ci_lty |
Line type for the confidence levels. |
... |
Arguments passed on to |
Returns and plots a trellis
object.
Original by Brian Ripley.
lattice::xyplot()
, stats::plot.acf()
, stats::acf()
.
z <- ts(matrix(rnorm(400), 100, 4), start = c(1961, 1), frequency = 12) xyplot(acf(z))
z <- ts(matrix(rnorm(400), 100, 4), start = c(1961, 1), frequency = 12) xyplot(acf(z))
Diagnostic plots modelled after stats::tsdiag()
with some modifications
and corrections of p-values in the Box–Ljung test.
## S3 method for class 'Arima' xyplot( x, data = NULL, which = 1:4, lag.max = NULL, gof.lag = NULL, qq.aspect = "iso", na.action = na.pass, main = NULL, layout = NULL, ... )
## S3 method for class 'Arima' xyplot( x, data = NULL, which = 1:4, lag.max = NULL, gof.lag = NULL, qq.aspect = "iso", na.action = na.pass, main = NULL, layout = NULL, ... )
x |
A fitted time-series model of class |
data |
Ignored |
which |
A sequence of integers between 1 and 4, identifying the plots to be shown. |
lag.max |
Number of lags to compute ACF for. |
gof.lag |
The maximum number of lags for the Ljung–Box test. |
qq.aspect |
Aspect of Q-Q plot (see |
na.action |
Treatment of |
main |
Optional titles for the plots. Can also be |
layout |
Either a numeric vector with (columns, rows) to use in the call
to |
... |
Parameters to pass to |
Plots a lattice plot and returns a trellis
object.
stats::tsdiag()
, stats::arima()
, lattice::xyplot()
,
gridExtra::grid.arrange()
, stats::Box.test()
.
fit <- arima(lh, order = c(1, 1, 0)) xyplot(fit, layout = c(2, 2)) xyplot(fit, which = c(1:2, 4), layout = rbind(c(1, 1), c(2, 3)))
fit <- arima(lh, order = c(1, 1, 0)) xyplot(fit, layout = c(2, 2)) xyplot(fit, which = c(1:2, 4), layout = rbind(c(1, 1), c(2, 3)))
Plot forecasts from forecast::forecast()
. It is built mostly to resemble
the forecast::autoplot.forecast()
and forecast::plot.forecast()
functions, but in addition tries to plot the predictions on the original
scale.
## S3 method for class 'forecast' xyplot( x, data = NULL, ci = TRUE, ci_levels = x$level, ci_key = ci, ci_pal = hcl(0, 0, 45:100), ci_alpha = trellis.par.get("regions")$alpha, ... )
## S3 method for class 'forecast' xyplot( x, data = NULL, ci = TRUE, ci_levels = x$level, ci_key = ci, ci_pal = hcl(0, 0, 45:100), ci_alpha = trellis.par.get("regions")$alpha, ... )
x |
An object of class |
data |
Data of observations left out of the model fit, usually "future" observations. |
ci |
Plot confidence intervals for the predictions. |
ci_levels |
The prediction levels to plot as a subset of those
forecasted in |
ci_key |
Set to |
ci_pal |
Color palette for the confidence bands. |
ci_alpha |
Fill alpha for the confidence interval. |
... |
Arguments passed on to |
This function requires the zoo package.
An object of class "trellis"
. The
update
method can be used to
update components of the object and the
print
method (usually called by
default) will plot it on an appropriate plotting device.
lattice::panel.xyplot()
, forecast::forecast()
, lattice::xyplot.ts()
.
if (require(forecast)) { train <- window(USAccDeaths, c(1973, 1), c(1977, 12)) test <- window(USAccDeaths, c(1978, 1), c(1978, 12)) fit <- arima(train, order = c(0, 1, 1), seasonal = list(order = c(0, 1, 1))) fcast1 <- forecast(fit, 12) xyplot(fcast1, test, grid = TRUE, auto.key = list(corner = c(0, 0.99)), ci_key = list(title = "PI Level")) # A fan plot fcast2 <- forecast(fit, 12, level = seq(0, 95, 10)) xyplot(fcast2, test, ci_pal = heat.colors(100)) }
if (require(forecast)) { train <- window(USAccDeaths, c(1973, 1), c(1977, 12)) test <- window(USAccDeaths, c(1978, 1), c(1978, 12)) fit <- arima(train, order = c(0, 1, 1), seasonal = list(order = c(0, 1, 1))) fcast1 <- forecast(fit, 12) xyplot(fcast1, test, grid = TRUE, auto.key = list(corner = c(0, 0.99)), ci_key = list(title = "PI Level")) # A fan plot fcast2 <- forecast(fit, 12, level = seq(0, 95, 10)) xyplot(fcast2, test, ci_pal = heat.colors(100)) }
Lattice plot diagnostics for lm
objects, mostly mimicking the behavior
of stats::plot.lm()
but based on lattice::xyplot()
instead.
## S3 method for class 'lm' xyplot( x, data = NULL, which = c(1:3, 5), main = FALSE, id.n = 3, labels.id = names(residuals(x)), cex.id = 0.75, cook.levels = c(0.5, 1), label.pos = c(4, 2), layout = NULL, ... )
## S3 method for class 'lm' xyplot( x, data = NULL, which = c(1:3, 5), main = FALSE, id.n = 3, labels.id = names(residuals(x)), cex.id = 0.75, cook.levels = c(0.5, 1), label.pos = c(4, 2), layout = NULL, ... )
x |
|
data |
Only provided for method consistency and is ignored. |
which |
if a subset of the plots is required, specify a subset of the
numbers |
main |
if |
id.n |
number of points to be labelled in each plot, starting with the most extreme. |
labels.id |
vector of labels, from which the labels for extreme
points will be chosen. |
cex.id |
magnification of point labels. |
cook.levels |
levels of Cook's distance at which to draw contours. |
label.pos |
positioning of labels, for the left half and right half of the graph respectively, for plots 1-3, 5, 6. |
layout |
a numeric vector with |
... |
arguments to be passed to |
A list of trellis
objects or a single trellis
object.
Original by John Maindonald and Martin Maechler. Adaptation to lattice by Johan Larsson.
stats::lm()
, stats::plot.lm()
, lattice::xyplot()
fit <- lm(Sepal.Length ~ Sepal.Width, data = iris) xyplot(fit) xyplot(fit, which = 5)
fit <- lm(Sepal.Length ~ Sepal.Width, data = iris) xyplot(fit) xyplot(fit, which = 5)