Rev 5489 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
\name{B_01_xyplot}\title{Common Bivariate Trellis Plots}\alias{xyplot}\alias{xyplot.formula}\alias{barchart}\alias{barchart.formula}\alias{barchart.numeric}\alias{barchart.default}\alias{bwplot}\alias{bwplot.formula}\alias{bwplot.numeric}\alias{dotplot}\alias{dotplot.formula}\alias{dotplot.numeric}\alias{dotplot.default}\alias{stripplot}\alias{stripplot.formula}\alias{stripplot.numeric}\usage{xyplot(x, data, \dots)dotplot(x, data, \dots)barchart(x, data, \dots)stripplot(x, data, \dots)bwplot(x, data, \dots)\method{xyplot}{formula}(x,data,allow.multiple = is.null(groups) || outer,outer = !is.null(groups),auto.key = FALSE,aspect = "fill",panel = lattice.getOption("panel.xyplot"),prepanel = NULL,scales = list(),strip = TRUE,groups = NULL,xlab,xlim,ylab,ylim,drop.unused.levels = lattice.getOption("drop.unused.levels"),\dots,lattice.options = NULL,default.scales,subscripts = !is.null(groups),subset = TRUE)\method{dotplot}{formula}(x,data,panel = lattice.getOption("panel.dotplot"),\dots)\method{barchart}{formula}(x,data,panel = lattice.getOption("panel.barchart"),box.ratio = 2,\dots)\method{stripplot}{formula}(x,data,panel = lattice.getOption("panel.stripplot"),\dots)\method{bwplot}{formula}(x,data,allow.multiple = is.null(groups) || outer,outer = FALSE,auto.key = FALSE,aspect = "fill",panel = lattice.getOption("panel.bwplot"),prepanel = NULL,scales = list(),strip = TRUE,groups = NULL,xlab,xlim,ylab,ylim,box.ratio = 1,horizontal = NULL,drop.unused.levels = lattice.getOption("drop.unused.levels"),\dots,lattice.options = NULL,default.scales,subscripts = !is.null(groups),subset = TRUE)}\description{These are the most commonly used high level Trellis functions to plotpairs of variables. By far the most common is \code{xyplot}, designedmainly for two continuous variates (though factors can be supplied aswell, in which case they will simply be coerced to numeric), whichproduces Conditional Scatter plots. The others are useful when one ofthe variates is a factor or a shingle. Most of these arguments arealso applicable to other high level functions in the lattice package,but are only documented here.}\arguments{\item{x}{The object on which method dispatch is carried out.For the \code{"formula"} methods, a formula describing the form ofconditioning plot. The formula is generally of the form \code{y ~ x| g1 * g2 * \dots}, indicating that plots of \code{y} (on the yaxis) versus \code{x} (on the x axis) should be produced conditionalon the variables \code{g1, g2, \dots}. However, the conditioningvariables \code{g1,g2,\dots} may be omitted. The formula can also besupplied as \code{y ~ x | g1 + g2 + \dots}.For all of these functions, with the exception of \code{xyplot}, aformula of the form \code{ ~ x | g1 * g2 * \dots} is alsoallowed. In that case, \code{y} defaults to \code{names(x)} if\code{x} is named, and a factor with a single level otherwise.Other usage of the form \code{dotplot(x)} is handled by methoddispatch as appropriate. The \code{numeric} method is equivalent toa call with no left hand side and no conditioning variables in theformula. For \code{barchart} and \code{dotplot}, non-trivialmethods exist for tables and arrays, documented under\code{\link{barchart.table}}.The conditioning variables \code{g1, g2, \dots} must be eitherfactors or shingles. Shingles are a way of processing numericvariables for use in conditioning. See documentation of\code{\link{shingle}} for details. Like factors, they have a\code{"levels"} attribute, which is used in producing theconditional plots.Numeric conditioning variables are converted to shingles by thefunction \code{shingle} (however, using \code{\link{equal.count}}might be more appropriate in many cases) and character vectors arecoerced to factors.The formula can involve expressions, e.g. \code{sqrt()},\code{log()}.A special case is when the left and/or right sides of the formula(before the conditioning variables) contain a \sQuote{+} sign, e.g.,\code{y1+y2 ~ x | a*b}. This formula would be taken to mean that theuser wants to plot both \code{y1~x | a*b} and \code{y2~x | a*b}, butwith the \code{y1~x} and \code{y2~x} superposed in each panel (thisis slightly more complicated in \code{barchart}). The two partswould be distinguished by different graphical parameters. This isessentially what the \code{groups} argument would produce, if\code{y1} and \code{y2} were concatenated to produce a longervector, with the \code{groups} argument being an indicator of whichrows come from which variable. In fact, this is exactly what isdone internally using the \code{\link{reshape}} function. Thisfeature cannot be used in conjunction with the \code{groups}argument.To interpret \code{y1 + y2} as a sum, one can either set\code{allow.multiple=FALSE} or use \code{I(y1+y2)}.A variation on this feature is when the \code{outer} argument is setto \code{TRUE} as well as \code{allow.multiple}. In that case, theplots are not superposed in each panel, but instead separated intodifferent panels (as if a new conditioning variable had been added).The \code{x} and \code{y} variables should both be numeric in\code{xyplot}, and an attempt is made to coerce them ifnot. However, if either is a factor, the levels of that factor areused as axis labels. In the other four functions documented here,exactly one of \code{x} and \code{y} should be numeric, and theother a factor or shingle. Which of these will happen is determinedby the \code{horizontal} argument --- if \code{horizontal=TRUE},then \code{y} will be coerced to be a factor or shingle, otherwise\code{x}. The default value of \code{horizontal} is \code{FALSE} if\code{x} is a factor or shingle, \code{TRUE} otherwise. (Thefunctionality provided by \code{horizontal=FALSE} is notS-compatible.)Note that this argument used to be called \code{formula} in earlierversions (when the high level functions were not generic and theformula method was essentially the only method). This is no longerallowed. It is recommended that this argument not be named in anycase, but rather be the first (unnamed) argument.% All points with at least one of its values missing (NA) in any% of the variates involved are omitted from the plot.}\item{data}{For the \code{formula} method, a data frame containing values (ormore precisely, anything that is a valid \code{envir} argument in\code{\link{eval}}, e.g. a list or an environment) for any variables inthe formula, as well as \code{groups} and \code{subset} ifapplicable. If not found in \code{data}, or if \code{data} isunspecified, the variables are looked for in the environment of theformula. For other methods (where \code{x} is not a formula),\code{data} is usually ignored, often with a warning.}\item{allow.multiple, outer}{logical flags to control what happens with formulas like \code{y1 +y2 ~ x}. See the entry for \code{x} for details.\code{allow.multiple} defaults to \code{TRUE} whenever it makessense, and \code{outer} defaults to \code{FALSE} except when\code{groups} is explicitly specified or grouping doesn't make sensefor the default panel function}\item{box.ratio}{ applicable to \code{bwplot}, \code{barchart} and\code{stripplot}, specifies the ratio of the width of the rectanglesto the inter rectangle space.}\item{horizontal}{ logical, applicable to \code{bwplot, dotplot,barchart} and \code{stripplot}. Determines which of \code{x} and\code{y} is to be a factor or shingle (\code{y} if TRUE, \code{x}otherwise). Defaults to \code{FALSE} if \code{x} is a factor orshingle, \code{TRUE} otherwise. This argument is used to process thearguments to these high level functions, but more importantly, it ispassed as an argument to the panel function, which is supposed touse it as appropriate.A potentially useful component of \code{scales} in this case mightbe \code{abbreviate = TRUE}, in which case long labels which wouldusually overlap will be abbreviated. \code{scales} could alsocontain a \code{minlength} argument in this case, which would bepassed to the \code{abbreviate} function.}% \item{jitter.data}{% logical specifying whether the values should be jittered by adding a% random noise in stripplot. This is actually an argument of% \code{panel.stripplot}.% }% \item{factor}{% numeric controlling amount of jitter as in \code{\link{jitter}}.% }The following arguments are common to all the functions documentedhere, as well as most other high level Trellis functions. These arenot documented elsewhere, except to override the usage given here.\item{panel}{Once the subset of rows defined by each unique combination of thelevels of the grouping variables are obtained (see details), thecorresponding \code{x} and \code{y} variables (or other variables,as appropriate, in the case of other high level functions) arepassed on to be plotted in each panel. The actual plotting is doneby the function specified by the \code{panel} argument. Each highlevel function has its own default panel function, which coulddepend on whether the \code{groups} argument was supplied.The panel function can be a function object or a character stringgiving the name of a predefined function.Much of the power of Trellis Graphics comes from the ability todefine customized panel functions. A panel function appropriatefor the functions described here would usually expect argumentsnamed \code{x} and \code{y}, which would be provided by theconditioning process. It can also have other arguments. It might beuseful to know in this context that all arguments passed to a highlevel Trellis function (such as \code{xyplot}) that are notrecognized by it are passed through to the panel function. It isthus generally good practice when defining panel functions to allowa \code{\dots} argument. Such extra arguments typically controlgraphical parameters, but other uses are also common. Seedocumentation for individual panel functions for specifics.Note that unlike in S-PLUS, it is not guaranteed that panelfunctions will be supplied only numeric vectors for the \code{x} and\code{y} arguments; they can be factors as well (but notshingles). Panel functions need to handle this case, which in mostcases can be done by simply coercing them to numeric.Technically speaking, panel functions must be written using Gridgraphics functions. However, knowledge of Grid is usually notnecessary to construct new custom panel functions, there are severalpredefined panel functions which can help; for example,\code{panel.grid}, \code{panel.loess}, etc. There are also somegrid-compatible replacements of commonly used base R graphicsfunctions useful for this purpose. For example, \code{lines} can bereplaced by \code{llines} (or equivalently, \code{panel.lines}).Note that base R graphics functions like \code{lines} will not workin a lattice panel function.One case where a bit more is required of the panel function is whenthe \code{groups} argument is not null. In that case, the panelfunction should also accept arguments named \code{groups} and\code{subscripts} (see below for details). A useful panel functionpredefined for use in such cases is \code{panel.superpose}, whichcan be combined with different \code{panel.groups} functionsdetermining what is plotted for each group. See the examplessection for an interaction plot constructed in this way. Severalother panel functions can also handle the \code{groups} argument,including the default ones for \code{barchart}, \code{dotplot} and\code{stripplot}.Even when \code{groups} is not present, the panel function can have\code{subscripts} as a formal argument. In either case, the\code{subscripts} argument passed to the panel function are theindices of the \code{x} and \code{y} data for that panel in theoriginal \code{data}, BEFORE taking into account the effect ofthe \code{subset} argument. Note that \code{groups} remainsunaffected by any subsetting operations, so\code{groups[subscripts]} gives the values of \code{groups} thatcorrespond to the data in that panel.This interpretation of \code{subscripts} does not hold when theextended formula interface is in use (i.e., when\code{allow.multiple} is in effect). A comprehensive descriptionwould be too complicated (details can be found in the source code ofthe function \code{latticeParseFormula}), but in short, the extendedinterface works by creating an artificial grouping variable that islonger than the original data frame, and consequently,\code{subscripts} needs to refer to rows beyond those in theoriginal data. To further complicate matters, the artificialgrouping variable is created after any effect of \code{subset}, inwhich case \code{subscripts} has practically no relationship withcorresponding rows in the original data frame.One can also use functions called \code{\link{panel.number}} and\code{\link{packet.number}}, representing panel order and packetorder respectively, inside the panel function (as well as the stripfunction or while interacting with a lattice display using\code{\link{trellis.focus}} etc). Both provide a simple integerindex indicating which panel is currently being drawn, but differ inhow the count is calculated. The panel number is a simpleincremental counter that starts with 1 and is incremented each timea panel is drawn. The packet number on the other hand indexes thecombination of levels of the conditioning variables that isrepresented by that panel. The two indices coincide unless theorder of conditioning variables is permuted and/or the plottingorder of levels within one or more conditioning variables is altered(using \code{perm.cond} and \code{index.cond} respectively), inwhich case \code{packet.number} gives the index corresponding to the\sQuote{natural} ordering of that combination of levels of theconditioning variables.\code{\link{panel.xyplot}} has an argument called \code{type} whichis worth mentioning here because it is quite frequently used (and asmentioned above, can be passed to \code{xyplot} directly). In theevent that a \code{groups} variable is used,\code{\link{panel.xyplot}} calls \code{\link{panel.superpose}},arguments of which can also be passed directly to \code{xyplot}.Panel functions for \code{bwplot} and friends should have anargument called \code{horizontal} to account for the cases when\code{x} is the factor or shingle.}% \item{panel.groups}{% useful mostly for \code{xyplot} and \code{densityplot}. Applies when% \code{panel} is \code{panel.superpose} (which happens by default in% these cases if \code{groups} is non-null)% }\item{aspect}{ controls physical aspect ratio of the panels (same forall the panels). It can be specified as a ratio (verticalsize/horizontal size) or as a character string. Legitimatevalues are \code{"fill"} (the default) which tries to make thepanels as big as possible to fill the available space; \code{"xy"},which \bold{tries} to compute the aspect based on the 45 degreebanking rule (see \emph{Visualizing Data} by William S. Clevelandfor details); and \code{"iso"} for isometric scales, where therelation between physical distance on the device and distance in thedata scale are forced to be the same for both axes.If a \code{prepanel} function is specified and it returns components\code{dx} and \code{dy}, these are used for banking calculations.Otherwise, values from the default prepanel function are used.Currently, only the default prepanel function for \code{xyplot} canbe expected to produce sensible banking calculations. See\code{\link{banking}} for details on the implementation of banking .}\item{groups}{ a variable or expression to be evaluated in the dataframe specified by \code{data}, expected to act as a groupingvariable within each panel, typically used to distinguish differentgroups by varying graphical parameters like color and line type.Formally, if \code{groups} is specified, then \code{groups} alongwith \code{subscripts} is passed to the panel function, which isexpected to handle these arguments. Not all pre-defined panelfunctions know how to, but for high level functions where groupingis appropriate, the default panel functions are chosen so that theydo.It is very common to use a key (legend) when a groupingvariable is specified. See entries for \code{key}, \code{auto.key}and \code{\link{simpleKey}} for how to draw a key.}\item{auto.key}{A logical (indicating whether a key is to be drawn automatically whena grouping variable is present in the plot), or a list of parametersthat would be valid arguments to \code{\link{simpleKey}} (in effect,most valid components of \code{key} can be specified in thismanner). If \code{auto.key} is not \code{FALSE}, \code{groups} isnon-null and there is no \code{key} or \code{legend} argumentspecified in the call, a key is created with \code{simpleKey} with\code{levels(groups)} as the first argument. (Note: this may notwork in all high level functions, but it does work for the oneswhere grouping makes sense with the default panel function)\code{simpleKey} uses the trellis settings to determine thegraphical parameters in the key, so this will be meaningful only ifthe settings are used in the plot as well.One disadvantage to using \code{key} (or even \code{simpleKey})directly is that the graphical parameters used in the key areabsolutely determined at the time when the \code{"trellis"} object iscreated. Consequently, if a plot once created is re-\code{print}edwith different settings, the parameter settings for the originaldevice will be used. However, with \code{auto.key}, the key isactually created at printing time, so the key settings will matchthe device settings.}\item{prepanel}{function that takes the same arguments as the \code{panel} functionand returns a list, possibly containing components named\code{xlim}, \code{ylim}, \code{dx} and \code{dy} (and lessfrequently, \code{xat} and \code{yat}).The \code{xlim} and \code{ylim} components are similar to the highlevel \code{xlim} and \code{ylim} arguments (i.e., they are usuallya numeric vector of length 2 defining a range of values, or acharacter vector representing levels of a factor). If the\code{xlim} and \code{ylim} arguments are not explicitly specified(possibly as components in \code{scales}), then the actual limits ofthe panels are guaranteed to include the limits returned by theprepanel function. This happens globally if the \code{relation}component of \code{scales} is \code{"same"}, and on a panel by panelbasis otherwise. See \code{xlim} to see what forms of the components\code{xlim} and \code{ylim} are allowed.The \code{dx} and \code{dy} components are used for bankingcomputations in case \code{aspect} is specified as \code{"xy"}. Seedocumentation for the function \code{banking} for details regardinghow this is done.The return value of the prepanel function need not have all thecomponents named above; in case some are missing, they are replacedby the usual component-wise defaults.If \code{xlim} or \code{ylim} is a character vector (which isappropriate when the corresponding variable is a factor), thisimplicitly indicates that the scale should include the first\code{n} integers, where \code{n} is the length of \code{xlim} or\code{ylim}, as the case may be. The elements of the charactervector are used as the default labels for these \code{n} integers.Thus, to make this information consistent between panels, the\code{xlim} or \code{ylim} values should represent all the levels ofthe corresponding factor, even if some are not used within thatparticular panel.In such cases, an additional component \code{xat} or \code{yat} maybe returned by the \code{prepanel} function, which should be asubset of \code{1:n}, indicating which of the \code{n} values(levels) are actually represented in the panel. This is useful whencalculating the limits with \code{relation="free"} or\code{relation="sliced"} in \code{scales}.The prepanel function is responsible for providing a meaningfulreturn value when the \code{x}, \code{y} (etc.) variables arezero-length vectors. When nothing is appropriate, values of NAshould be returned for the \code{xlim} and \code{ylim} components.}\item{strip}{logical flag or function. If \code{FALSE}, strips are not drawn.Otherwise, strips are drawn using the \code{strip} function, whichdefaults to \code{strip.default}. See documentation of\code{strip.default} to see the arguments that are available to thestrip function. This description also applies to the\code{strip.left} argument (see \code{\dots} below), which can beused to draw strips on the left of each panel, which can be usefulfor wide short panels, e.g. in time series plots.}\item{xlab}{ character string or expression (or a \code{"grob"}) givinglabel for the x-axis. Defaults to the expression for \code{x} in\code{formula}. Can be specified as \code{NULL} to omit the labelaltogether. Finer control is possible, as described in the entryfor \code{main}, with the additional feature that if the\code{label} component is omitted from the list, it is replaced bythe default \code{xlab}.}\item{ylab}{ character string or expression (or \code{"grob"}) givinglabel for the y-axis. Defaults to the expression for \code{y} in\code{formula}. Fine control is possible, see entries for\code{main} and \code{xlab}.}\item{scales}{ list determining how the x- and y-axes (tick marks andlabels) are drawn. The list contains parameters in\code{name=value} form, and may also contain two other lists called\code{x} and \code{y} of the same form (described below).Components of \code{x} and \code{y} affect the respective axes only,while those in \code{scales} affect both. When parameters arespecified in both lists, the values in \code{x} or \code{y} areused. Note that certain high-level functions have defaults that arespecific to a particular axis (e.g., \code{bwplot} has\code{alternating=FALSE} for the y-axis only); these can beoverridden only by an entry in the corresponding component of\code{scales}.The possible components are :\describe{\item{\code{relation}}{character string that determines how axis limits are calculatedfor each panel. Possible values are \code{"same"} (default),\code{"free"} and \code{"sliced"}. For \code{relation="same"},the same limits, usually large enough to encompass all the data,are used for all the panels. For \code{relation="free"}, limitsfor each panel is determined by just the points in that panel.Behavior for \code{relation="sliced"} is similar, except thatthe length (max - min) of the scales are constrained to remainthe same across panels.The determination of what axis limits are suitable for eachpanel can be controlled by the \code{prepanel} function, whichcan be overridden by \code{xlim}, \code{ylim} or\code{scales$limits}. If relation is not \code{"same"}, thevalue of \code{xlim} etc is normally ignored, except when it isa list, in which case it is treated as if its components werethe limit values obtained from the prepanel calculations foreach panel.}\item{\code{tick.number}}{Suggested number of ticks (ignored for a factor, shingle orcharacter vector, in which case there is no natural rule forleaving out some of the labels. But see \code{xlim}).}\item{\code{draw}}{logical, defaults to \code{TRUE}, whether to draw the axis atall.}\item{\code{alternating}}{logical specifying whether axis labels should alternate from oneside of the group of panels to the other. For finer control,alternating can be a vector (replicated to be as long as thenumber of rows or columns per page) consisting of the followingnumbers\itemize{\item 0: do not draw tick labels\item 1: bottom/left\item 2: top/right\item 3: both.}\code{alternating} applies only when \code{relation="same"}.The default is \code{TRUE}, or equivalently, \code{c(1, 2)}}\item{\code{limits}}{same as xlim and ylim.}\item{\code{at}}{ location of tick marks along the axis (in nativecoordinates), or a list as long as the number of panelsdescribing tick locations for each panel.}\item{\code{labels}}{Labels (strings or expressions) to go along with \code{at}. Canbe a list like \code{at} as well.}\item{\code{cex}}{numeric multiplier to control character sizes for axis labels.Can be a vector of length 2, to control left/bottom andright/top separately.}\item{\code{font}, \code{fontface}, \code{fontfamily}}{specifies font for axis labels.}\item{\code{tck}}{numeric to control length of tick marks. Can be a vector oflength 2, to control left/bottom and right/top separately.}\item{\code{col}}{color of ticks and labels.}\item{\code{rot}}{Angle by which the axis labels are to be rotated. Can be avector of length 2, to control left/bottom and right/topseparately.}\item{\code{abbreviate}}{logical, whether to abbreviate the labels using\code{abbreviate}. Can be useful for long labels (e.g., infactors), especially on the x-axis.}\item{\code{minlength}}{argument passed to \code{abbreviate} if \code{abbreviate=TRUE}.}\item{\code{log}}{Controls whether the corresponding variable (\code{x} or\code{y}) will be log transformed before being passed to thepanel function. Defaults to \code{FALSE}, inwhich case the data are not transformed. Other possible valuesare any number that works as a base for taking logarithm,\code{TRUE} (which is equivalent to 10), and \code{"e"} (for thenatural logarithm). As a side effect, the corresponding axis islabeled differently. Note that this is a transformation of thedata, not the axes. Other than the axis labeling, using thisfeature is no different than transforming the data in theformula; e.g., \code{scales=list(x = list(log = 2))} isequivalent to \code{y ~ log2(x)}.% whether to use a log scale. Defaults to \code{FALSE}, other% possible values are any number that works as a base for taking% logarithm, \code{TRUE}, equivalent to 10, and \code{"e"} (for% natural logarithm). Note that in this case the values passed to% the panel function are already transformed, so all computations% done inside the panel function will be affected accordingly. For% example, \code{panel.lmline} will fit a line to the transformed% values.}\item{\code{format}}{the \code{format} to use for POSIXct variables. See\code{\link{strptime}} for description of valid values.}\item{\code{axs}}{character, \code{"r"} or \code{"i"}. In the latter case, theaxis limits are calculated as the exact data range, instead ofbeing padded on either side. (May not always work as expected.)}}Note that much of the function of \code{scales} is accomplished by\code{pscales} in \code{splom}.}\item{subscripts}{logical specifying whether or not a vector named \code{subscripts}should be passed to the panel function. Defaults to \code{FALSE},unless \code{groups} is specified, or if the panel function acceptsan argument named \code{subscripts}. (One should be careful whendefining the panel function on-the-fly.)}\item{subset}{logical or integer indexing vector (can be specified in terms ofvariables in \code{data}). Only these rows of \code{data} will beused for the plot. If \code{subscripts} is \code{TRUE}, thesubscripts will provide indices to the rows of data before thesubsetting is done. Whether levels of factors in the data framethat are unused after the subsetting will be dropped depends on the\code{drop.unused.levels} argument.}\item{xlim}{ Normally a numeric vector of length 2 (possibly aDateTime object) giving minimum and maximum for the x-axis, or, acharacter vector, expected to denote the levels of \code{x}. Thelatter form is interpreted as a range containing c(1, length(xlim)),with the character vector determining labels at tick positions\code{1:length(xlim)}\code{xlim} could also be a list, with as many components as thenumber of panels (recycled if necessary), with each component asdescribed above. This is meaningful only when\code{scales$x$relation} is \code{"free"} or \code{"sliced"}, inwhich case these are treated as if they were the corresponding limitcomponents returned by prepanel calculations.}\item{ylim}{ similar to \code{xlim}, applied to the y-axis. }\item{drop.unused.levels}{logical indicating whether the unused levels of factors will bedropped, usually relevant with a subsetting operation is performedor an \code{\link{interaction}} is created. Unused levels areusually dropped, but it is sometimes appropriate to suppressdropping to preserve a useful layout. For finer control, thisargument could also be list containing components \code{cond} and\code{data}, both logical, indicating desired behavior forconditioning variables and data variables respectively. The defaultis given by \code{lattice.getOption("drop.unused.levels")}, whichis initially set to \code{TRUE} for both components. Note that thisargument does not control dropping of levels of the \code{groups}argument.}\item{ default.scales }{list giving the default values of \code{scales} for a particularhigh level function. This should not be of any interest to thenormal user, but may be helpful when defining other functions thatact as a wrapper to one of the high level lattice functions.}\item{lattice.options}{a list that could be supplied to \code{\link{lattice.options}}.These options are temporarily in effect for the duration of thecall, after which the settings revert back to whatever they werebefore. The settings are also retained along with the object andreused during plotting. This enables the user to attach optionssettings to the trellis object itself rather than change thesettings globally. See also the \code{par.settings} argumentdescribed below for a similar treatment of graphical settings.}\item{\dots}{ further arguments, usually not directly processed by thehigh level functions documented here, but rather passed on to otherfunctions. Such arguments can be broadly categorized into two types:those that affect all high level Trellis functions in a similarmanner, and those that are meant for the specific panel functionused, which may differ across high level functions.The first group of arguments are processed by a common, unexportedfunction called \code{trellis.skeleton}. These arguments affect allhigh level functions, but are only documented here, except tooverride the behaviour described here. All other argumentsspecified in a high level call, specifically those neither describedhere nor in the help page of the relevant high level function, arepassed unchanged to the panel function used. By convention, thedefault panel function used for any high level function is named as\code{"panel."} followed by the name of the high level function;for example, the default panel function for \code{bwplot} is\code{panel.bwplot}. In practical terms, this means that inaddition to the help page of the high level function being used, theuser should also consult the help page of the corresponding panelfunction for arguments that may be specified in the high level call.The effect of the first group of common arguments are as follows:\describe{\item{\code{as.table}:}{ logical that controls the order in which panelsshould be plotted: if \code{FALSE} (the default), panels are drawnleft to right, bottom to top (as in a graph); if \code{TRUE}, leftto right, top to bottom.}\item{\code{between}:}{ a list with components \code{x} and \code{y} (bothusually 0 by default), numeric vectors specifying the space betweenthe panels (units are character heights). \code{x} and \code{y} arerepeated to account for all panels in a page and any extracomponents are ignored. The result is used for all pages in amulti page display. (In other words, it is not possible to usedifferent \code{between} values for different pages).}\item{\code{key}:}{A list of arguments that define a legend to be drawn on the plot.This list is used as an argument to the \code{\link{draw.key}}function, which produces a grid object eventually plotted by theprint method for \code{"trellis"} objects.There is also a less flexible but usually sufficient shortcutfunction \code{\link{simpleKey}} that can generate such a list, aswell as the argument \code{auto.key} that can be convenient in themost common situation where legends are used, namely when there is agrouping variable. To use more than one legend, or to have arbitrarylegends not constrained by the structure imposed by \code{key}, usethe \code{legend} argument.The position of the key can be controlled in either of twopossible ways. If a component called \code{space} is present,the key is positioned outside the plot region, in one of thefour sides, determined by the value of \code{space}, which canbe one of \code{"top"}, \code{"bottom"}, \code{"left"} and\code{"right"}. Alternatively, the key can be positioned insidethe plot region by specifying components \code{x}, \code{y} and\code{corner}. \code{x} and \code{y} determine the location ofthe corner of the key given by \code{corner}, which is usuallyone of \code{c(0,0)}, \code{c(1,0)}, \code{c(1,1)} and\code{c(0,1)}, which denote the corners of the unit square.Fractional values are also allowed, in which case \code{x} and\code{y} determine the position of an arbitrary point inside (oroutside for values outside the unit interval) the key.\code{x} and \code{y} should be numbers between 0 and 1, givingcoordinates with respect to the \dQuote{display area}.Depending on the value of\code{lattice.getOption("legend.bbox")}, this can be either thefull figure region (\code{"full"}), or just the region thatbounds the panels and strips (\code{"panel"}).The key essentially consists of a number of columns, possiblydivided into blocks, each containing some rows. The contents of thekey are determined by (possibly repeated) components named\code{"rectangles"}, \code{"lines"}, \code{"points"} or\code{"text"}. Each of these must be lists with relevant graphicalparameters (see later) controlling their appearance. The \code{key}list itself can contain graphical parameters, these would be used ifrelevant graphical components are omitted from the other components.The length (number of rows) of each such column (except \code{"text"}s)is taken to be the largest of the lengths of the graphicalcomponents, including the ones specified outside (see the entry for\code{rep} below for details on this). The \code{"text"} component has tohave a character or expression vector as its first component, andthe length of this vector determines the number of rows.The graphical components that can be included in \code{key} (andalso in the components named \code{"text"}, \code{"lines"},\code{"points"} and \code{"rectangles"} as appropriate) are:\itemize{\item \code{cex=1}\item \code{col="black"}\item \code{alpha=1}\item \code{lty=1}\item \code{lwd=1}\item \code{font=1}\item \code{fontface}\item \code{fontfamily}\item \code{pch=8}\item \code{adj=0}\item \code{type="l"}\item \code{size=5}\item \code{angle=0}\item \code{density=-1}}In addition, the component \code{border} can be included insidethe \code{"rect"} component to control the border color of therectangles; when specified at the top level, \code{border}controls the border of the entire key (see below).\code{angle} and \code{density} are unimplemented. \code{size}determines the width of columns of rectangles and lines incharacter widths. \code{type} is relevant for lines; \code{"l"}denotes a line, \code{"p"} denotes a point, and \code{"b"} and\code{"o"} both denote both together.Other possible components of \code{key} are:\describe{\item{\code{reverse.rows}}{logical, defaulting to \code{FALSE}. If \code{TRUE}, allcomponents are reversed \emph{after} being replicated(the details of which may depend on the value of\code{rep}). This is useful in certain situations,e.g. with a grouped \code{barchart} with \code{stack =FALSE} with the categorical variable on the vertical axis,where the bars in the plot will usually be ordered frombottom to top, but the corresponding legend will have thelevels from top to bottom (unless, of course,\code{reverse.rows = TRUE}). Note that in this case, unlessall columns have the same number or rows, they will nolonger be aligned.}\item{\code{between}}{numeric vector giving the amount of space (character widths)surrounding each column (split equally on both sides)}\item{\code{title}}{string or expression giving a title for the key}\item{\code{rep}}{logical, defaults to \code{TRUE}. By default, it's assumed thatall columns in the key (except the \code{"text"}s) will have the samenumber of rows, and all components are replicated to be as longas the longest. This can be suppressed by specifying\code{rep=FALSE}, in which case the length of each column willbe determined by components of that column alone.}\item{\code{cex.title}}{cex for the title}\item{\code{lines.title}}{how many lines the title should occupy (in multiples ofitself). Defaults to 2.}\item{\code{padding.text}}{how much space (padding) should be used above and below eachrow containing text, in multiples of the default, which iscurrently \code{0.2 * "lines"}. This padding is in addition tothe normal height of any row that contains text, which is theminimum amount necessary to contain all the text entries.}\item{\code{background}}{background color, defaults to default background}\item{\code{alpha.background}}{An alpha transparency value between 0 and 1}\item{\code{border}}{either a color for the border, or a logical. In the lattercase, the border color is black if \code{border} is\code{TRUE}, and no border is drawn if it is \code{FALSE} (thedefault)}\item{\code{transparent=FALSE}}{logical, whether key area should have a transparent background}\item{\code{columns}}{the number of columns column-blocks the key is to be dividedinto, which are drawn side by side.}\item{\code{between.columns}}{Space between column blocks, in addition to \code{between}.}\item{\code{divide}}{Number of point symbols to divide each line when \code{type} is\code{"b"} or \code{"o"} in \code{lines}.}}}\item{\code{legend}:}{the legend argument can be useful if one wants to place more thanone key. It also allows one to use arbitrary \code{"grob"}s (gridobjects) as legends.If used, \code{legend} must be a list, with an arbitrary number ofcomponents. Each component must be named one of \code{"left"},\code{"right"}, \code{"top"}, \code{"bottom"} or \code{"inside"}.The name \code{"inside"} can be repeated, but not the others. Thisname will be used to determine the location for that component, andis similar to the \code{space} component of \code{key}. If\code{key} (or \code{colorkey} for \code{\link{levelplot}} and\code{\link{wireframe}}) is specified, their \code{space} componentmust not conflict with the name of any component of \code{legend}.Each component of \code{legend} must have a component called\code{fun}. This can be a \code{"grob"}, or a function or the name of afunction that produces a \code{"grob"} when called. If this functionexpects any arguments, they must be supplied as a list in anothercomponent called \code{args}. For components named \code{"inside"},there can be additional components called \code{x}, \code{y} and\code{corner}, which work in the same way as it does for \code{key}.}\item{\code{page}:}{ a function of one argument (page number) to be calledafter drawing each page. The function must be\sQuote{grid-compliant}, and is called with the whole display areaas the default viewport.}\item{\code{main}:}{ typically a character string or expressiondescribing the main title to be placed on top of each page.Defaults to \code{NULL}. \code{main} (as well as \code{xlab},\code{ylab} and \code{sub}) is usually a character string or anexpression that gets used as the label, but can also be a listthat controls further details. Expressions are treated asspecification of LaTeX-like markup as described in\code{\link{plotmath}}. The label can be a vector, in whichcase the components will be spaced out horizontally (orvertically for \code{ylab}). This feature can be used toprovide column or row labels rather than a single axis label.When \code{main} (etc.) is a list, the actual label should bespecified as the \code{label} component (which may be unnamed ifit is the first component). The label can be missing, in whichcase the default will be used (\code{xlab} and \code{ylab}usually have defaults, but \code{main} and \code{sub} do not).Further named arguments are passed on to\code{\link[grid:grid.text]{textGrob}}; this can includearguments controlling positioning like \code{just} and\code{rot} as well as graphical parameters such as \code{col}and \code{font} (see \code{\link[grid:gpar]{gpar}} for a fulllist).\code{main}, \code{xlab}, \code{ylab} and \code{sub} can also bean arbitrary \code{"grob"} (grid graphical object).}\item{\code{sub}:}{character string or expression (or a list or \code{"grob"}) fora subtitle to be placed at the bottom of each page. See entryfor \code{main} for finer control options.}\item{\code{par.strip.text}:}{ list of parameters to control the appearanceof strip text. Notable components are \code{col}, \code{cex},\code{font} and \code{lines}. The first three control graphicalparameters while the last is a means of altering the height of thestrips. This can be useful, for example, if the strip labels(derived from factor levels, say) are double height (i.e., contains\code{"\\n"}-s) or if the default height seems too small or toolarge. The \code{lineheight} component can control the spacebetween multiple lines. Also, the labels can be abbreviated whenshown by specifying \code{abbreviate = TRUE}, in which case thecomponents \code{minlength} and \code{dot} (passed along to the\code{\link{abbreviate}} function) can be specified to control thedetails of how this is done.}\item{\code{layout}:}{In general, a Trellis conditioning plot consists of several panelsarranged in a rectangular array, possibly spanning multiplepages. \code{layout} determines this arrangement.\code{layout} is a numeric vector giving the number of columns, rowsand pages in a multi panel display. By default, the number ofcolumns is the number of levels of the first conditioning variableand the number of rows is the number of levels of the secondconditioning variable. If there is only one conditioning variable,the default layout vector is \code{c(0,n)}, where \code{n} is thenumber of levels of the given vector. Any time the first value inthe layout vector is 0, the second value is used as the desirednumber of panels per page and the actual layout is computed fromthis, taking into account the aspect ratio of the panels and thedevice dimensions (via \code{par("din")}). The number of pages isby default set to as many as is required to plot all the panels. Ingeneral, giving a high value of \code{layout[3]} is not wastefulbecause blank pages are never created.}\item{\code{skip}:}{logical vector (default \code{FALSE}), replicated to be as long asthe number of panels (spanning all pages). For elements that are\code{TRUE}, the corresponding panel position is skipped; i.e.,nothing is plotted in that position. The panel that was supposed tobe drawn there is now drawn in the next available panel position,and the positions of all the subsequent panels are bumped upaccordingly. This is often useful for arranging plots in aninformative manner.}\item{\code{strip.left}:}{% FIXME: (update: fix what?)\code{strip.left} can be used to draw strips on the left of eachpanel, which can be useful for wide short panels, as in timeseries (or similar) plots. It is a function similar to\code{strip}.}\item{\code{xlab.default}, \code{ylab.default}:}{ fallback defaultfor \code{xlab} and \code{ylab} when they are not specified. If\code{NULL}, the defaults are parsed from the Trellis formula.This is rarely useful for the end-user, but can be helpful whendeveloping new Trellis functions.}\item{\code{xscale.components, yscale.components}:}{functions that determine axis annotation for the x and y axesrespectively. See documentation for\code{\link{xscale.components.default}}, the default values ofthese arguments, to learn more. }\item{\code{axis}:}{ function that draws axis annotation. Seedocumentation for \code{\link{axis.default}}, the default valueof this argument, to learn more. }\item{\code{perm.cond}:}{numeric vector, a permutation of \code{1:n}, where \code{n} is thenumber of conditioning variables. By default, the order in whichpanels are drawn depends on the order of the conditioning variablesspecified in the \code{formula}. \code{perm.cond} can modify thisorder. If the trellis display is thought of as an\code{n}-dimensional array, then during printing, its dimensions arepermuted using \code{perm.cond} as the \code{perm} argument to\code{\link{aperm}}.}\item{\code{index.cond}:}{While \code{perm.cond} permutes the dimensions of themultidimensional array of panels, \code{index.cond} can be usedto subset (or reorder) margins of that array. \code{index.cond}can be a list or a function, with behavior in each casedescribed below.The panel display order within each conditioning variabledepends on the order of their levels. \code{index.cond} can beused to choose a \sQuote{subset} (in the R sense) of theselevels, which is then used as the display order for thatvariable. If \code{index.cond} is a list, it has to be as longas the number of conditioning variables, and the \code{i}-thcomponent has to be a valid indexing vector for\code{levels(g_i)}, where \code{g_i} is the \code{i}-thconditioning variable in the plot (note that these levels maynot contain all levels of the original variable, depending onthe effects of the \code{subset} and \code{drop.unused.levels}arguments). In particular, this indexing may repeat levels, ordrop some altogether. The result of this indexing determinesthe order of panels within that conditioning variable. To keepthe order of a particular variable unchanged, the correspondingcomponent must be set to \code{TRUE}.Note that the components of \code{index.cond} are in the order ofthe conditioning variables in the original call, and is not affectedby \code{perm.cond}.Another possibility is to specify \code{index.cond} as a function.In this case, this function is called once for each panel,potentially with all arguments that are passed to the panel functionfor that panel. (More specifically, if this function has a\code{\dots} argument, then all panel arguments are passed,otherwise, only named arguments that match are passed.) For a singleconditioning variable, the levels of that variable are then sortedso that these values are in ascending order. For multipleconditioning variables, the order for each variable is determined byfirst taking the average over all other conditioning variables.Although they can be supplied in high level function calls directly,it is more typical to use \code{perm.cond} and \code{index.cond} toupdate an existing \code{"trellis"} object, thus allowing it to bedisplayed in a different arrangement without re-calculating the datasubsets that go into each panel. In the \code{update} method, bothcan be set to \code{NULL}, which reverts these back to theirdefaults.}\item{\code{par.settings}:}{a list that could be supplied to \code{\link{trellis.par.set}}.This enables the user to attach some display settings to the trellisobject itself rather than change the settings globally. When theobject is plotted, these settings are temporarily in effect forthe duration of the plot, after which the settings revert backto whatever they were before.}\item{\code{plot.args}:}{a list of possible arguments to \code{\link{plot.trellis}},which will be used by the \code{plot} or \code{print} methodswhen drawing the object, unless overridden explicitly. Thisenables the user to attach such arguments to the trellis objectitself. Partial matching is not performed.}}}}\value{An object of class \code{"trellis"}. The\code{\link[lattice:update.trellis]{update}} method can be used toupdate components of the object and the\code{\link[lattice:print.trellis]{print}} method (usually called bydefault) will plot it on an appropriate plotting device.}\details{All the functions documented here are generic, with the \code{formula}method usually doing the actual work. The structure of the plot thatis produced is mostly controlled by the formula. For each uniquecombination of the levels of the conditioning variables \code{g1, g2,\dots}, a separate panel is produced using the points \code{(x,y)}for the subset of the data (also called packet) defined by thatcombination. The display can be though of as a 3-dimensional array ofpanels, consisting of one 2-dimensional matrix per page. Thedimensions of this array are determined by the \code{layout} argument.If there are no conditioning variables, the plot produced consists ofa single panel.The coordinate system used by lattice by default is like a graph,with the origin at the bottom left, with axes increasing to left andup. In particular, panels are by default drawn starting from thebottom left corner, going right and then up; unless \code{as.table =TRUE}, in which case panels are drawn from the top left corner,going right and then down. One might wish to set a global preferencefor a table-like arrangement by changing the default to\code{as.table=TRUE}; this can be done by setting\code{lattice.options(default.args = list(as.table = TRUE))}. Infact, default values can be set in this manner for the followingarguments: \code{as.table}, \code{aspect}, \code{between},\code{page}, \code{main}, \code{sub}, \code{par.strip.text},\code{layout}, \code{skip} and \code{strip}. Note that these globaldefaults are sometimes overridden by individual functions.The order of the panels depends on the order in which the conditioningvariables are specified, with \code{g1} varying fastest. Within aconditioning variable, the order depends on the order of the levels(which for factors is usually in alphabetical order). Both of theseorders can be modified using the \code{index.cond} and\code{perm.cond} arguments, possibly using the\code{\link[lattice:update.trellis]{update}} (and other related)method(s).}\note{Most of the arguments documented here are also applicable for theother high level functions in the lattice package. These are notdescribed in any detail elsewhere unless relevant, and this should beconsidered the canonical documentation for such arguments.Any arguments passed to these functions and not recognized by themwill be passed to the panel function. Most predefined panel functionshave arguments that customize its output. These arguments aredescribed only in the help pages for these panel functions, but canusually be supplied as arguments to the high level plot.}\references{Sarkar, Deepayan (2008) "Lattice: Multivariate Data Visualization withR", Springer. \url{http://lmdvr.r-forge.r-project.org/}}\seealso{\code{\link{Lattice}} for an overview of the package, as well as\code{\link{barchart.table}},\code{\link{print.trellis}},\code{\link{shingle}},\code{\link{banking}},\code{\link{reshape}},\code{\link{panel.xyplot}},\code{\link{panel.bwplot}},\code{\link{panel.barchart}},\code{\link{panel.dotplot}},\code{\link{panel.stripplot}},\code{\link{panel.superpose}},\code{\link{panel.loess}},\code{\link{panel.linejoin}},\code{\link{strip.default}},\code{\link{simpleKey}}\code{\link{trellis.par.set}}}\author{ Deepayan Sarkar \email{Deepayan.Sarkar@R-project.org}}\examples{\dontrun{## wait for user input before each new page (like 'par(ask = TRUE)')old.prompt <- grid::grid.prompt(TRUE)}require(stats)## Tonga Trench EarthquakesDepth <- equal.count(quakes$depth, number=8, overlap=.1)xyplot(lat ~ long | Depth, data = quakes)update(trellis.last.object(),strip = strip.custom(strip.names = TRUE, strip.levels = TRUE),par.strip.text = list(cex = 0.75),aspect = "iso")## Examples with data from `Visualizing Data' (Cleveland)## (obtained from Bill Cleveland's Homepage :## http://cm.bell-labs.com/cm/ms/departments/sia/wsc/, also## available at statlib)EE <- equal.count(ethanol$E, number=9, overlap=1/4)## Constructing panel functions on the fly; prepanelxyplot(NOx ~ C | EE, data = ethanol,prepanel = function(x, y) prepanel.loess(x, y, span = 1),xlab = "Compression Ratio", ylab = "NOx (micrograms/J)",panel = function(x, y) {panel.grid(h=-1, v= 2)panel.xyplot(x, y)panel.loess(x,y, span=1)},aspect = "xy")## with and without bankingplot <- xyplot(sunspot.year ~ 1700:1988, xlab = "", type = "l",scales = list(x = list(alternating = 2)),main = "Yearly Sunspots")print(plot, position = c(0, .3, 1, .9), more = TRUE)print(update(plot, aspect = "xy", main = "", xlab = "Year"),position = c(0, 0, 1, .3))## Multiple variables in formula for grouped displaysxyplot(Sepal.Length + Sepal.Width ~ Petal.Length + Petal.Width | Species,data = iris, scales = "free", layout = c(2, 2),auto.key = list(x = .6, y = .7, corner = c(0, 0)))## user defined panel functionsstates <- data.frame(state.x77,state.name = dimnames(state.x77)[[1]],state.region = state.region)xyplot(Murder ~ Population | state.region, data = states,groups = state.name,panel = function(x, y, subscripts, groups)ltext(x = x, y = y, labels = groups[subscripts], cex=1,fontfamily = "HersheySans"))barchart(yield ~ variety | site, data = barley,groups = year, layout = c(1,6),ylab = "Barley Yield (bushels/acre)",scales = list(x = list(abbreviate = TRUE,minlength = 5)))barchart(yield ~ variety | site, data = barley,groups = year, layout = c(1,6), stack = TRUE,auto.key = list(points = FALSE, rectangles = TRUE, space = "right"),ylab = "Barley Yield (bushels/acre)",scales = list(x = list(rot = 45)))bwplot(voice.part ~ height, data=singer, xlab="Height (inches)")dotplot(variety ~ yield | year * site, data=barley)dotplot(variety ~ yield | site, data = barley, groups = year,key = simpleKey(levels(barley$year), space = "right"),xlab = "Barley Yield (bushels/acre) ",aspect=0.5, layout = c(1,6), ylab=NULL)stripplot(voice.part ~ jitter(height), data = singer, aspect = 1,jitter.data = TRUE, xlab = "Height (inches)")## Interaction Plotxyplot(decrease ~ treatment, OrchardSprays, groups = rowpos,type = "a",auto.key =list(space = "right", points = FALSE, lines = TRUE))## longer version with no x-ticks\dontrun{bwplot(decrease ~ treatment, OrchardSprays, groups = rowpos,panel = "panel.superpose",panel.groups = "panel.linejoin",xlab = "treatment",key = list(lines = Rows(trellis.par.get("superpose.line"),c(1:7, 1)),text = list(lab = as.character(unique(OrchardSprays$rowpos))),columns = 4, title = "Row position"))}\dontrun{grid::grid.prompt(old.prompt)}}\keyword{hplot}