B_00_xyplot | R Documentation |
This help page documents several commonly used high-level Lattice
functions. xyplot
produces bivariate scatterplots or
time-series plots, bwplot
produces box-and-whisker plots,
dotplot
produces Cleveland dot plots, barchart
produces
bar plots, and stripplot
produces one-dimensional scatterplots.
All these functions, along with other high-level Lattice functions,
respond to a common set of arguments that control conditioning,
layout, aspect ratio, legends, axis annotation, and many other details
in a consistent manner. These arguments are described extensively in
this help page, and should be used as the reference for other
high-level functions as well.
For control and customization of the actual display in each panel, the help page of the respective default panel function will often be more informative. In particular, these help pages describe many arguments commonly used when calling the corresponding high-level function but are specific to them.
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 = lattice.getOption("default.args")$auto.key,
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,
default.prepanel = lattice.getOption("prepanel.default.xyplot"),
subscripts = !is.null(groups),
subset = TRUE)
## S3 method for class 'data.frame'
xyplot(x, data = NULL, formula = data, ...)
## S3 method for class 'formula'
dotplot(x,
data,
panel = lattice.getOption("panel.dotplot"),
default.prepanel = lattice.getOption("prepanel.default.dotplot"),
...)
## S3 method for class 'data.frame'
dotplot(x, data = NULL, formula = data, ...)
## S3 method for class 'formula'
barchart(x,
data,
panel = lattice.getOption("panel.barchart"),
default.prepanel = lattice.getOption("prepanel.default.barchart"),
box.ratio = 2,
...)
## S3 method for class 'data.frame'
barchart(x, data = NULL, formula = data, ...)
## S3 method for class 'formula'
stripplot(x,
data,
panel = lattice.getOption("panel.stripplot"),
default.prepanel = lattice.getOption("prepanel.default.stripplot"),
...)
## S3 method for class 'data.frame'
stripplot(x, data = NULL, formula = data, ...)
## S3 method for class 'formula'
bwplot(x,
data,
allow.multiple = is.null(groups) || outer,
outer = FALSE,
auto.key = lattice.getOption("default.args")$auto.key,
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,
default.prepanel = lattice.getOption("prepanel.default.bwplot"),
subscripts = !is.null(groups),
subset = TRUE)
## S3 method for class 'data.frame'
bwplot(x, data = NULL, formula = data, ...)
x |
All high-level function in lattice are generic. For the For the functions documented here, the formula is generally of the
form With the exception of Cases where The conditioning variables Extended formula interface: As a useful extension of the
interface described above, the primary variable terms (both the LHS
To interpret A variation on this feature is when the Primary variables: The Note that the |
data |
For the |
formula |
The formula to be used for the |
allow.multiple |
Logical flag specifying whether the extended formula interface
described above should be in effect. Defaults to |
outer |
Logical flag controlling what happens with formulas using the
extended interface described above (see the entry for |
box.ratio |
Applicable to |
horizontal |
Logical flag applicable to A potentially useful component of |
Common arguments: The following arguments are common to all the functions documented here, as well as most other high-level Trellis functions. These are not documented elsewhere, except to override the usage given here.
panel |
Once the subset of rows defined by each unique combination of the
levels of the grouping variables are obtained (see
“Details”), the corresponding Much of the power of Trellis Graphics comes from the ability to
define customized panel functions. A panel function appropriate for
the functions described here would usually expect arguments named
Note that unlike in S-PLUS, it is not guaranteed that panel
functions will be supplied only numeric vectors for the Technically speaking, panel functions must be written using Grid
graphics functions. However, knowledge of Grid is usually not
necessary to construct new custom panel functions, as there are
several predefined panel functions which can help; for example,
One case where a bit more is required of the panel function is when
the Even when This interpretation of One can also use functions called
|
aspect |
This argument controls the physical aspect ratio of the panels,
which is usually the same for all the panels. It can be specified as
a ratio (vertical size/horizontal size) or as a character string.
In the latter case, legitimate values are If a |
groups |
A variable or expression to be evaluated in It is very common to use a key (legend) when a grouping variable is
specified. See entries for |
auto.key |
A logical, or a list containing components to be used as arguments
to
More precisely, if Note that One disadvantage to using |
prepanel |
A function that takes the same arguments as the The The If In such cases, an additional component The prepanel function is responsible for providing a meaningful
return value when the |
strip |
A logical flag or function. If |
xlab |
Character or expression (or a |
ylab |
Character or expression (or |
scales |
Generally a list determining how the x- and y-axes (tick marks and
labels) are drawn. The list contains parameters in
As a special exception, The possible components are :
Note that much of the function of |
subscripts |
A logical flag specifying whether or not a vector named
|
subset |
An expression that evaluates to a logical or integer indexing
vector. Like |
xlim |
Normally a numeric vector (or a DateTime object) of length 2 giving
left and right limits for the x-axis, or a character vector,
expected to denote the levels of
|
ylim |
Similar to |
drop.unused.levels |
A logical flag indicating whether the unused levels of factors will
be dropped, usually relevant when a subsetting operation is
performed or an |
default.scales |
A list giving the default values of |
default.prepanel |
A function or character string giving the name of a function that
serves as the (component-wise) fallback prepanel function when the
|
lattice.options |
A list that could be supplied to |
... |
Further arguments, usually not directly processed by the high-level functions documented here, but instead passed on to other functions. Such arguments can be broadly categorized into two types: those that affect all high-level Lattice functions in a similar manner, and those that are meant for the specific panel function being used. The first group of arguments are processed by a common, unexported
function called The effect of the first group of common arguments are as follows:
|
The high-level functions documented here, as well as other high-level
Lattice functions, are generic, with the formula
method usually
doing the most substantial work. The structure of the plot that is
produced is mostly controlled by the formula (implicitly in the case
of the non-formula methods). For each unique combination of the
levels of the conditioning variables g1, g2, ...
, a separate
“packet” is produced, consisting of the points (x,y)
for
the subset of the data defined by that combination. The display can
be thought of as a three-dimensional array of panels, consisting of one
two-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 packet.
Each packet usually corresponds to one panel, but this is not strictly
necessary (see the entry for index.cond
above).
The coordinate system used by lattice by default is like a
graph, with the origin at the bottom left, with axes increasing to the
right and top. 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. It is possible to set a
global preference for the 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))
. 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, followed by
g2
, and so on. 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).
The high-level functions documented here, as well as other high-level
Lattice functions, return an object of class "trellis"
. The
update
method can be used to
subsequently update components of the object, and the
print
method (usually called by
default) will plot it on an appropriate plotting device.
Most of the arguments documented here are also applicable for the other high-level functions in the lattice package. These are not described in any detail elsewhere unless relevant, and this should be considered the canonical documentation for such arguments.
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.
Deepayan Sarkar Deepayan.Sarkar@R-project.org
Sarkar, Deepayan (2008) Lattice: Multivariate Data Visualization with R, Springer. http://lmdvr.r-forge.r-project.org/
Lattice
for an overview of the package, as well as
barchart.table
,
print.trellis
,
shingle
,
banking
,
reshape
,
panel.xyplot
,
panel.bwplot
,
panel.barchart
,
panel.dotplot
,
panel.stripplot
,
panel.superpose
,
panel.loess
,
panel.average
,
strip.default
,
simpleKey
trellis.par.set
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")
## Extended formula interface
xyplot(Sepal.Length + Sepal.Width ~ Petal.Length + Petal.Width | Species,
data = iris, scales = "free", layout = c(2, 2),
auto.key = list(x = .75, y = .75, corner = c(0.5, 0.5)))
## 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,
snames = states$state.name,
panel = function(x, y, subscripts, snames) {
panel.text(x = x, y = y, labels = snames[subscripts], cex = 1,
fontfamily = "HersheySans")
})
## Stacked bar chart
barchart(yield ~ variety | site, data = barley,
groups = year, layout = c(1,6), stack = TRUE,
auto.key = list(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)
## Grouped dot plot showing anomaly at Morris
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
## Not run:
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"))
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.