xyplot
, designed
mainly for two continuous variates (though factors can be supplied as
well, in which case they will simply be coerced to numeric), which
produces Conditional Scatter plots. The others are useful when one of
the variates is a factor or a shingle. Most of these arguments are
also applicable to other high level functions in the lattice package,
but are only documented here.xyplot(x, data, ...)
dotplot(x, data, ...)
barchart(x, data, ...)
stripplot(x, data, ...)
bwplot(x, data, ...)## S3 method for class 'formula':
xyplot(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"),
...,
lattice.options = NULL,
default.scales,
subscripts = !is.null(groups),
subset = TRUE)
## S3 method for class 'formula':
dotplot(x,
data,
panel = lattice.getOption("panel.dotplot"),
...)
## S3 method for class 'formula':
barchart(x,
data,
panel = lattice.getOption("panel.barchart"),
box.ratio = 2,
...)
## S3 method for class 'formula':
stripplot(x,
data,
panel = lattice.getOption("panel.stripplot"),
...)
## S3 method for class 'formula':
bwplot(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"),
...,
lattice.options = NULL,
default.scales,
subscripts = !is.null(groups),
subset = TRUE)
For the "formula"
methods, a formula describing the form of
conditioning plot. The formula is generally of the form y ~ x
| g1 * g2 * ...
, indicating that plots o
formula
method, a data frame containing values (or
more precisely, anything that is a valid envir
argument in
eval
, e.g. a list or an environment) for any variables iny1 +
y2 ~ x
. See the entry for x
for details.
allow.multiple
defaults to TRUE
whenever it makes
sense, and outer
defaulbwplot
, barchart
and
stripplot
, specifies the ratio of the width of the rectangles
to the inter rectangle space.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 x
and y
variables (or other variables,
as appropriate, in the case of ot"fill"
(the default) which tries to make the
data
, expected to act as a grouping
variable within each panel, typically used to distinguish different
groups by varying graphical parameters like color and simpleKey
(in effect,
panel
function
and returns a list, possibly containing components named
xlim
, ylim
, dx
and dy
(and less
frequently, xat
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 th"grob"
) giving
label for the x-axis. Defaults to the expression for x
in
formula
. Can be specified as NULL
to omit the label
altogether. Finer control "grob"
) giving
label for the y-axis. Defaults to the expression for y
in
formula
. Fine control is possible, see entries for
main
and xlab
.name=value
form, and may also contain two other lists called
x
and y
of the same form (described subscripts
should be passed to the panel function. Defaults to FALSE
,
unless groups
is specified, or if the panel function accepts
an argument named data
). Only these rows of data
will be
used for the plot. If subscripts
is TRUE
, the
subscripts will provide inx
. The
latter form is interpreted as a range containing c(1, lxlim
, applied to the y-axis.interaction
is created. Unused levels are
usually drscales
for a particular
high level function. This should not be of any interest to the
normal user, but may be helpful when defining other functions that
act as a wrapper to one of the high levellattice.options
.
These options are temporarily in effect for the duration of the
call, after which the settings revert back to whatever they were
before.formula
method usually doing the actual work. The structure of the plot that
is produced is mostly controlled by the formula. For each unique
combination of the levels of the conditioning variables g1, g2,
...
, a separate panel is produced using the points (x,y)
for the subset of the data (also called packet) defined by that
combination. The display can be though of as a 3-dimensional array of
panels, consisting of one 2-dimensional matrix per page. The
dimensions of this array are determined by the layout
argument.
If there are no conditioning variables, the plot produced consists of
a 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 and
up. In particular, panels are by default drawn starting from the
bottom left corner, going right and then up; unless 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 preference
for a table-like arrangement by changing the default to
as.table=TRUE
; this can be done by setting
lattice.options(default.args = list(as.table = TRUE))
. In
fact, default values can be set in this manner for the following
arguments: as.table
, aspect
, between
,
page
, main
, sub
, par.strip.text
,
layout
, skip
and strip
. Note that these global
defaults are sometimes overridden by individual functions.
The order of the panels depends on the order in which the conditioning
variables are specified, with g1
varying fastest. Within a
conditioning variable, the order depends on the order of the levels
(which for factors is usually in alphabetical order). Both of these
orders can be modified using the index.cond
and
perm.cond
arguments, possibly using the
update
(and other related)
method(s).
Lattice
for an overview of the package, as well as
barchart.table
,
Lattice
,
print.trellis
,
shingle
,
banking
,
reshape
,
panel.xyplot
,
panel.bwplot
,
panel.barchart
,
panel.dotplot
,
panel.stripplot
,
panel.superpose
,
panel.loess
,
panel.linejoin
,
strip.default
,
simpleKey
trellis.par.set
## wait for user input before each new page (like 'par(ask = TRUE)')
old.prompt <- grid::grid.prompt(TRUE)
require(stats)
## Tonga Trench Earthquakes
Depth <- 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; 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")
## with and without banking
plot <- 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 displays
xyplot(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 functions
states <- 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 Plot
xyplot(decrease ~ treatment, OrchardSprays, groups = rowpos,
type = "a",
auto.key =
list(space = "right", points = FALSE, lines = TRUE))
## longer version with no x-ticks
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"))
grid::grid.prompt(old.prompt)
Run the code above in your browser using DataLab