Learn R Programming

lattice (version 0.5-4)

xyplot: Common Bivariate Trellis Plots

Description

These are the most commonly used Trellis functions to look at pairs of variables. By far the most common is xyplot, designed mainly for two continuous variates, which produces Conditional Scatterplots. The others are useful when one of the variates is a factor. See details below.

Most of the arguments documented here are also applicable for many of the other Trellis functions. These are not described in any detail elsewhere, and this should be considered the canonical documentation for such arguments.

Note that any arguments passed to these functions and not recognized by them will be passed to the panel function. Most predefined panel functions have arguments that customize its output. These arguments are described only in the help pages for these panel functions, but can usually be supplied as arguments to the high level plot.

Usage

xyplot(formula,
       data = parent.frame(),
       panel = "panel.xyplot",
       aspect = "fill",
       as.table = FALSE,
       between,
       groups,
       key,
       layout,
       main,
       page,
       par.strip.text,
       prepanel,
       scales,
       skip,
       strip = "strip.default",
       sub,
       xlab,
       xlim,
       ylab,
       ylim,
       ...,
       subscripts,
       subset)
barchart(formula, data, panel = "panel.barchart", box.ratio = 2,
         horizontal, ...)
bwplot(formula, data, panel = "panel.bwplot", box.ratio = 1,
       horizontal, ...)
dotplot(formula, data, panel = "panel.dotplot", ...)
stripplot(formula, data, panel = "panel.stripplot",
          jitter = FALSE, factor = .5, box.ratio, ...)

Arguments

formula
a formula describing the form of conditioning plot. The formula is generally of the form y ~ x | g1 * g2 * ..., indicating that plots of y (on the y axis) versus x (on the x axis) should be produced condi
data
a data frame containing values for any variables in the formula, as well as groups and subset if applicable. By default the environment where the function was called from is used.
box.ratio
gives the ratio of the width of the rectangles to the inter rectangle space.
horizontal
logical, applicable to bwplot, dotplot, barchart and stripplot. Determines which of x and y is to be a factor or shingle (y if TRUE, x otherwise). Defaults to
jitter
logical specifying whether the values should be jittered by adding a random noise in stripplot.
factor
numeric controlling amount of jitter. Inverse effect compared to S ?
panel
Once the subset of rows defined by each unique combination of the levels of the grouping variables are obtained (see above), the corresponding x and y variables (or some other variables, as appropriate, in the case of
aspect
controls physical aspect ratio of the panels (same for all the panels). It can be specified as a ratio (vertical size/horizontal size) or as a character string. Legitimate values are "fill" (the default) which tries to make the panels as
as.table
logical that controls the order in which panels should be plotted: if FALSE, panels are drawn left to right, bottom to top (graph), if TRUE, left to right, top to bottom (matrix).
between
a list with components x and y (both usually 0 by default), numeric vectors specifying the space between the panels (units are character heights). x and y are repeated to account for all pane
groups
used typically with panel=panel.superpose to allow display controls (color, lty etc) to vary according to a grouping variable. Formally, if groups is specified, then groups along with subscripts is passed
key
A list of arguments that define a legend to be drawn on the plot.

The position of the legend can be controlled in either of two possible ways. If a component called space is present, the key is positioned outside the plot region

layout
In general, a Trellis conditioning plot consists of several panels arranged in a rectangular array, possibly spanning multiple pages. layout determines this arrangement.

layout is a numeric vector giving the number o

main
character string for main title to be placed on top of each page. Defaults to NULL. Can be a character string, or a list with components label, cex, col, font. The label tag can be omitted if it is the fi
page
a function of one argument (page number) to be called after drawing each page. The function must be `grid-compliant', and is called with the whole display area as the default viewport.
par.strip.text
list of graphical parameters to control the strip text, possible components are col, cex, font, lines. The first three control graphical parameters while the last is a means of altering the height of the strips. This can be useful
prepanel
function that takes arguments x,y (usually) and returns a list containing four components xlim, ylim, dx, dy. If xlim and ylim are not explicitly specified (possibly as components in
scales
list determining how the x- and y-axes (tick marks and labels) are drawn. The list contains parameters in name=value form, and may also contain two other lists called x and y of the same form (described below). Compon
skip
logical vector (default FALSE), replicated to be as long as the number of panels in each page. If TRUE, nothing is plotted in the corresponding panel. Useful for arranging plots in an informative manner.
strip
logical flag or function. If FALSE, strips are not drawn. Otherwise, strips are drawn using the strip function, which defaults to strip.default. See documentation of strip.default to see the
sub
character string for a subtitle to be placed at the bottom of each page. See entry for main for finer control options.
subscripts
logical specifying whether or not a vector named subscripts should be passed to the panel function. Defaults to FALSE, unless groups is specified, or if the panel function accepts an argument named subscripts. (One sh
subset
logical vector (can be specified in terms of variables in data). Everything will be done on the data points for which subset=TRUE. In case subscripts is TRUE, the subscripts will correspond to the origina
xlab
character string giving label for the x-axis. Defaults to the expression for x in formula. Specify as NULL to omit the label altogether. Fine control is possible, see entry for sub.
xlim
numeric vector of length 2 giving minimum and maximum for x-axis.
ylab
character string giving label for the y-axis. Defaults to the expression for y in formula. Fine control possible, see entry for xlab.
ylim
numeric vector of length 2 giving minimum and maximum for y-axis.
...
other arguments, passed to the panel function

synopsis

xyplot(formula, data = parent.frame(), aspect = "fill", layout = NULL, panel = panel.xyplot, prepanel = NULL, scales = list(), strip = TRUE, groups = NULL, xlab, xlim, ylab, ylim, ..., subscripts = !is.null(groups), subset = TRUE) barchart(formula, data = parent.frame(), panel = "panel.barchart", prepanel = NULL, strip = TRUE, box.ratio = 2, groups = NULL, horizontal, ..., subset = TRUE) bwplot(formula, data = parent.frame(), aspect = "fill", layout = NULL, panel = panel.bwplot, prepanel = NULL, scales = list(), strip = TRUE, groups = NULL, xlab, xlim, ylab, ylim, box.ratio = 1, horizontal, ..., subscripts = !missing(groups), subset = TRUE) dotplot(formula, data = parent.frame(), panel = "panel.dotplot", prepanel = NULL, strip = TRUE, groups = NULL, horizontal, ..., subset = TRUE) stripplot(formula, data = parent.frame(), panel = "panel.stripplot", prepanel = NULL, strip = TRUE, jitter = FALSE, factor = 0.5, box.ratio = if (jitter) 1 else 0, groups = NULL, horizontal, ..., subset = TRUE)

Details

These are for the most part decriptions generally applicable to all high level Lattice functions, with special emphasis on xyplot, bwplot etc. For other functions, their individual documentation should be studied in addition to this.

See Also

shingle, banking, panel.xyplot, panel.bwplot, panel.barchart, panel.dotplot, panel.stripplot, panel.superpose, panel.loess, panel.linejoin, strip.default, Lattice

Examples

Run this code
## Tonga Trench Earthquakes
data(quakes)
Depth <- equal.count(quakes$depth, number=8, overlap=.1)
xyplot(lat ~ long | Depth, data = quakes)

## 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)
data(ethanol)
EE <- equal.count(ethanol$E, number=9, overlap=1/4)
## Constructing panel functions on the fly; prepanel
xyplot(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")
## banking
data(sunspot)
xyplot(sunspot ~ 1:37 ,type = "l", aspect="xy",
       scales = list(y = list(log = TRUE)),
       sub = "log scales")

data(state)
## user defined panel functions
states <- data.frame(state.x77,
                     state.name = dimnames(state.x77)[[1]], 
                     state.region = state.region) 
xyplot(Murder ~ Population | state.region, data = states, 
       groups = as.character(state.name), 
       panel = function(x, y, subscripts, groups)  
       ltext(x=x, y=y, label=groups[subscripts], cex=.7, font=3))
data(barley)
barchart(yield ~ variety | year * site, data = barley, #aspect = 2.5,
         ylab = "Barley Yield (bushels/acre)",
         scales = list(x = list(0, abbreviate = TRUE,
                       minlength = 5)))
data(singer)
bwplot(voice.part ~ height, data=singer, xlab="Height (inches)")
dotplot(variety ~ yield | year * site, data=barley)
dotplot(variety ~ yield | site, data = barley, groups = year,
        panel = function(x, y, subscripts, ...) {
            dot.line <- trellis.par.get("dot.line")
            panel.abline(h = y, col = dot.line$col,
                         lty = dot.line$lty)
            panel.superpose(x, y, subscripts, ...)
        },
        key = list(space="right", transparent = TRUE,
                   points=list(pch=trellis.par.get("superpose.symbol")$pch[1:2],
                               col=trellis.par.get("superpose.symbol")$col[1:2]),
                   text=list(c("1932", "1931"))),
        xlab = "Barley Yield (bushels/acre) ",
        aspect=0.5, layout = c(1,6), ylab=NULL)
stripplot(voice.part ~ jitter(height), data = singer, aspect = 1,
          jitter = TRUE, xlab = "Height (inches)")
## Interaction Plot
data(OrchardSprays)
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"))

Run the code above in your browser using DataLab