The Latticeextra Package: R Topics Documented
The Latticeextra Package: R Topics Documented
The Latticeextra Package: R Topics Documented
Date 2007/10/20
LazyLoad yes
LazyData no
R topics documented:
SeatacWeather . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
USAge . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
USCancerRates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
ancestry . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
biocAccess . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
custom.theme . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
dendrogramGrob . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
ecdfplot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
gplot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
gplotArgs.data.frame . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
gvhd10 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
mapplot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
panel.3dmisc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
1
2 SeatacWeather
postdoc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
rootogram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
useOuterStrips . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
Index 24
Description
Daily Rainfall and Temperature at the Seattle-Tacoma Airport between January through March of
2007.
Usage
data(SeatacWeather)
Format
A data frame with 90 observations on the following 14 variables.
month a factor with levels January, February, and March
day day of the month
year year, all 2007
max.temp maximum temperature (Fahrenheit)
record.max record maximum temperature
normal.max normal maximum temperature
min.temp minimum temperature
record.min record minimum temperature
normal.min normal minimum temperature
precip precipitation (inches)
record.precip record precipitation
normal.precip normal precipitation
time.max time of maximum temperature
time.min time of minimum temperature
Details
The time of minimum and maximum temperatures should be interpreted as follows: the least two
significant digits denote minutes (out of 60) and the next two significant digits denote hout (out of
24).
Source
http://www.atmos.washington.edu/cgi-bin/list_climate.cgi?clisea
USAge 3
Description
US national population estimates by age and sex from 1900 to 1979. The data is available both as
a (3-dimensional) table and a data frame. The second form omits the 75+ age group to keep age
numeric.
Usage
data(USAge.table)
data(USAge.df)
Format
USAge.table is a 3-dimensional array with dimensions
No Name Levels
1 Age 0, 1, 2, . . . , 74, 75+
2 Sex Male, Female
3 Year 1900, 1901, . . . , 1979
Details
The data for 1900-1929 are rounded to thousands. The data for 1900-1939 exclude the Armed
Forces overseas and the population residing in Alaska and Hawaii. The data for 1940-1949 represent
the resident population plus Armed Forces overseas, but exclude the population residing in Alaska
and Hawaii. The data for 1950-1979 represent the resident population plus Armed Forces overseas,
and also include the population residing in Alaska and Hawaii.
Source
http://www.census.gov/popest/archives/pre-1980/PE-11.html U.S. Census
Bureau, Population Division. Internet Release date: October 1, 2004
The data were available as individual files for year, with varying levels for the margins. The prepro-
cessing steps used to reduce the data to the form given here are described in the scripts directory.
4 USCancerRates
Examples
data(USAge.table)
Description
This data set records the annual rates of death (1999-2003) due to cancer by sex in US counties.
Usage
data(USCancerRates)
Format
A data frame with 3041 observations on the following 8 variables.
rate.male a numeric vector, giving rate of death per 100,000 due to cancer among males
LCL95.male a 95% lower confidence limit for rate.male
UCL95.male a 95% upper confidence limit for rate.male
rate.female a numeric vector, giving rate of death per 100,000 due to cancer among females
LCL95.female a 95% lower confidence limit for rate.female
UCL95.female a 95% upper confidence limit for rate.female
state a factor with levels giving name of US state
county a character vector giving county names, in a format similar to that used for county map
boundaries in the maps package.
Details
See the scripts directory for details of data preprocessing steps.
From the website: Death data provided by the National Vital Statistics System public use data
file. Death rates calculated by the National Cancer Institute using SEER*Stat. Death rates are age-
adjusted to the 2000 US standard population [http://www.seer.cancer.gov/stdpopulations/
stdpop.19ages.html]. Population counts for denominators are based on Census populations
as modified by NCI.
Source
http://statecancerprofiles.cancer.gov/
Examples
data(USCancerRates)
ancestry 5
Description
This data set records the population and the three most frequently reported ancestries by US county,
according to the 2000 census.
Usage
data(ancestry)
Format
county A factor. An attempt has been made to make the levels look similar to the county names
used in the maps package.
population a numeric vector
top a character vector
second a character vector
third a character vector
Source
U.S. Census Bureau. The ancestry data were extracted from Summary File 3:
http://factfinder.census.gov/jsp/saff/SAFFInfo.jsp?_pageId=sp4_decennial_
sf3
which is based on the ‘long form’ questionnaire (asked to 1 in 6 households surveyed).
References
http://www.census.gov/prod/cen2000/doc/sf3.pdf
See Also
Description
This data set records the hourly number of access attempts to the Bioconductor website (http:
//www.bioconductor.org) during January through May of 2007. The counts are essentially
an aggregation of the number of entries in the access log.
Usage
data(biocAccess)
Format
A data frame with 3623 observations on the following 7 variables.
counts the number of access attempts
day the day of the month
month a factor with levels Jan, Feb, . . . , Dec
year the year (all 2007)
hour hour of the day, a numeric vector
weekday a factor with levels Monday, Tuesday, . . . , Sunday
time a POSIXt representation of the start of the hour
Examples
data(biocAccess)
plot(stl(ts(biocAccess$counts[1:(24 * 30)], frequency = 24), "periodic"))
Description
Creates a lattice theme given a few colors. Non-color settings are not included. The colors are
typically used to define the standard grouping (superposition) colors, and the first color is used for
ungrouped displays.
Usage
custom.theme(symbol = brewer.pal(n = 8, name = "Dark2"),
fill = brewer.pal(n = 12, name = "Set3"),
region = brewer.pal(n = 11, name = "Spectral"),
reference = "#e8e8e8",
bg = "transparent", fg = "black")
dendrogramGrob 7
Arguments
symbol a vector of symbol colors.
fill a vector of fill colors (for barcharts, etc.)
region a vector of colors that is used to define a continuous color gradient using colorRampPalette
reference a color for reference lines and such
bg a background color
fg a foreground color, primarily for annotation
Value
A list that can be supplied to trellis.par.get or as the theme argument to trellis.device.
Author(s)
Deepayan Sarkar
Description
This function creates a grob (a grid graphics object) that can be manipulated as such. In particular,
it can be used as a legend in a lattice display like levelplot to form heatmaps.
Usage
dendrogramGrob(x, ord = order.dendrogram(x),
side = c("right", "top"),
add = list(), size = 5, size.add = 1,
type = c("rectangle", "triangle"),
...)
Arguments
x An object of class "dendrogram". See dendrogram for details
ord A vector of integer indices giving the order in which the terminal leaves are to
be plotted. If this is not the same as order.dendrogram(x), then the leaves
may not cluster together and branches of the dendrogram may intersect.
side Intended position of the dendrogram when added in a heatmap. Currently al-
lowed positions are "right" and "top".
add Additional annotation. Currently, it is only possible to add one or more rows of
rectangles at the base of the dendrogram. See details below.
size Total height of the dendrogram in "lines" (see unit)
size.add Size of each additional row, also in "lines"
8 dendrogramGrob
type Whether a child node is joined to its parent directly with a straight line ("triangle")
or as a “stair” with two lines ("rectangle")
... Describe ... here
Details
The add argument can be used for additional annotation at the base of the dendrogram. It should
be a list with one component for each row, with names specifying the type of annotation and com-
ponents specifying the contents. Currently, the only supported name is "rect" (which can be
repeated), producing rectangles. The components in such a case is a list of graphical parameters,
possibly vectorized, that are passed on to gpar.
Value
An object of class "grob"
Author(s)
Deepayan Sarkar [email protected]
See Also
heatmap, levelplot
Examples
data(mtcars)
x <- t(as.matrix(scale(mtcars)))
dd.row <- as.dendrogram(hclust(dist(x)))
row.ord <- order.dendrogram(dd.row)
library(lattice)
levelplot(x[row.ord, col.ord],
aspect = "fill",
scales = list(x = list(rot = 90)),
colorkey = list(space = "left"),
legend =
list(right =
list(fun = dendrogramGrob,
args =
list(x = dd.col, ord = col.ord,
side = "right",
size = 10)),
top =
list(fun = dendrogramGrob,
args =
ecdfplot 9
list(x = dd.row,
side = "top",
type = "triangle"))))
levelplot(x[, col.ord],
aspect = "iso",
scales = list(x = list(rot = 90)),
colorkey = FALSE,
legend =
list(right =
list(fun = dendrogramGrob,
args =
list(x = dd.col, ord = col.ord,
side = "right",
size = 10)),
top =
list(fun = dendrogramGrob,
args =
list(x = dd.row, ord = sort(row.ord),
side = "top", size = 10,
type = "triangle"))))
Description
Conditional displays of Empirical Cumulative Distribution Functions
Usage
ecdfplot(x, data, ...)
Arguments
x For ecdfplot, x is the object on which method dispatch is carried out. For
the "formula" method, x is a formula describing the form of conditioning
plot, and has to be of the form ~x, where x is assumed to be a numeric vector.
Further conditioning variables are allowed as usual.
A similar interpretation holds for x in the "numeric" method as well as
prepanel.ecdfplot and panel.ecdfplot.
data For the "formula" method, a data frame containing values for any variables
in the formula, as well as those in groups and subset if applicable.
prepanel, panel
panel and prepanel function used to create the display.
xlab, ylab axis labels; typically a character string or an expression.
groups a grouing variable of the same length as x. If specified, ECDF plots are com-
puted for each subset defined by unique values of groups and the resulting
functions superposed within each panel.
f.value, qtype
Defines how quantiles are calculated. See panel.qqmath.
ref logical, whether a reference line should be drawn at 0 and 1
type how the plot is rendered; see panel.xyplot
Value
ecdfplot produces 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.
Author(s)
Deepayan Sarkar [email protected]
See Also
qqmath for Quantile plots which are more generally useful, especially when comparing with a
theoretical distribution other than uniform. An ECDF plot is essentially a transposed version (i.e.,
with axes switched) of a uniform quantile plot.
Examples
Description
Usage
gplot(x, ...)
gplotArgs(x, ...)
gplotArgs(x) <- value
## Default S3 method:
gplot(x, ...)
## Default S3 method:
gplotArgs(x, ...)
Arguments
Details
later.
Value
gplot should produce an object of class “trellis”. The ‘update’ method can be used to update com-
ponents of the object and the ‘print’ method (usually called by default) will plot it on an appropriate
plotting device.
gplotArgs should return a list.
Author(s)
See Also
Lattice
12 gplotArgs.data.frame
gplotArgs.data.frame
Grouped Display Arguments from a Data Frame
Description
Extract arguments suitable for gplot from a data.frame with appropriate meta-data
Usage
## S3 method for class 'data.frame':
gplotArgs(x, display.formula,
outer = FALSE, inner = FALSE, ...)
## S3 replacement method for class 'data.frame':
gplotArgs(x) <- value
Arguments
x an object of class “data.frame”
display.formula
a Trellis display formula
outer logical or one-sided formula
inner logical or one-sided formula
... extra arguments, passed on as appropriate
value a list containing named components, to be stored as special attributes of x, in-
cluding but not limited to
formula: a model formula with a response, covariate and grouping variable, i.e.
of the form y ~ x | g, where x could be 1
order.groups: logical, defaults to TRUE, whether levels of g will be reordered
for the plot
FUN: a function of x used to reorder levels of g, applied to subsets of x deter-
mined by g
outer: one-sided formula, defaults to NULL
inner: one-sided formula, defaults to NULL
labels: list of character strings (or expressions?) with named comonents, spec-
ifying variable names used in plot labels. The component names must be
variables in the data frame. Not all variables need be present (if not, the
variable names will be used for labels).
units: list, similar to labels, but specifying the units of measurement (if
present, used in constructing labels)
These are modeled on the groupedData function in package nlme, and are
stored as meta-data in the data frame x. The components listed above are spe-
cial in the sense that they are used by the corresponding gplotArgs method to
contruct a suitable list as descibed in gplotArgs.default. Any other com-
ponents in value can be used to override the values thus constructed, including
display.formula.
gvhd10 13
Details
The gplotArgs method for data frames constructs a suitable list as descibed in gplotArgs.default.
The display.formula argument can be used to specify the Trellis formula used (usually, it will
be constructed from the meta-data).
For the role of outer and more details, consult nlme documentation for now.
Value
gplotArgs should return a list.
Author(s)
Deepayan Sarkar [email protected]
See Also
gplot
Examples
gplotArgs(iris) <-
list(formula = Sepal.Length ~ 1 | Species,
order.groups = TRUE,
labels = list(Sepal.Length = "Sepal\nLength",
Sepal.Width = "Sepal\nWidth"))
gplot(iris)
gplot(iris, display.formula = Sepal.Length ~ Sepal.Width | Species)
Description
Flow cytometry data from blood samples taken from a Leukemia patient before and after allogenic
bone marrow transplant. The data spans five visits.
Usage
data(gvhd10)
Format
A data frame with 113896 observations on the following 8 variables.
Source
http://www.ficcs.org/software.html#Data_Files
References
Brinkman, R.R., et al. (2007). High-Content Flow Cytometry and Temporal Data Analysis for
Defining a Cellular Signature of Graft-Versus-Host Disease. Biology of Blood and Marrow Trans-
plantation 13–6
Description
Produces Trellis displays of numeric (and eventually categorical) data on a map. This is largely
meant as a demonstration, and users looking for serious map drawing capabilities should look else-
where (see below).
Usage
Arguments
x, y For mapplot, an object on which method dispatch is carried out. For the for-
mula method, a formula of the form y ~ x, with additional conditioning vari-
ables as desired. The extended form of conditioning using y ~ x1 + x2 etc.
is also allowed. The formula might be interpreted as in a dot plot, except that y
is taken to be the names of geographical units in map.
Suitable subsets (packets) of x and y are passed to the prepanel and panel func-
tions.
data A data source where names in the formula are evaluated
map An object of class "map" (package maps), containing boundary information.
The names of the geographical units must match the y variable in the formula.
outer logical; how variables separated by + in the formula are interpreted. It is not
advisable to change the default.
prepanel, panel
the prepanel and panel functions
aspect aspect ratio
breaks, cuts, colramp
controls conversion of numeric x values to a false colo. colramp may be a
vector of colors or a function that produces colors (such as cm.colors)
legend, colorkey
controls legends; usually just a color key giving the association between numeric
values of x and color.
lwd line width
... Further arguments passed on to the underlying engine. See xyplot for details.
Value
An object of class "trellis".
Note
This function is meant to demonstrate how maps can be incorporated in a Trellis display. Users
seriously interested in geographical data should consider using software written by people who
know what they are doing.
Author(s)
Deepayan Sarkar
References
http://en.wikipedia.org/wiki/Choropleth_map
See Also
Lattice
16 panel.3dmisc
Examples
library(maps)
library(mapproj)
data(USCancerRates)
data(ancestry)
county.map <-
map('county', plot = FALSE, fill = TRUE,
projection = "azequalarea")
## Not run:
county.areas <-
area.map(county.map, regions = county.map$names, sqmi = FALSE)
ancestry$density <-
with(ancestry, population / county.areas[as.character(county)])
## End(Not run)
Description
Miscellanous panel functions for use with three dimensional Lattice functions such as cloud and
wireframe
panel.3dmisc 17
Usage
panel.3dbars(x, y, z,
rot.mat = diag(4), distance,
xbase = 1, ybase = 1,
xlim, xlim.scaled,
ylim, ylim.scaled,
zlim, zlim.scaled,
zero.scaled,
col = "black",
lty = 1, lwd = 1,
alpha,
...,
col.facet = "white",
alpha.facet = 1)
Arguments
x, y, z data to be plotted
rot.mat, distance
arguments controlling projection
labels character or expression vectors to be uses as labels
xlim, ylim, zlim
limits in the original scale
xlim.scaled, ylim.scaled, zlim.scaled
limits after scaling
zero.scaled the value of z = 0 after scaling
xbase, ybase length of the sides of the bars (which are always centered on the x and y values).
Can not be vectorized.
col, lty, lwd, alpha, border
graphical parameters
18 postdoc
font, fontface
unused graphical parameters, present in the argument list only so that they can
be captured and ignored
col.facet, alpha.facet
graphical parameters for sides of the bars
... extra arguments, passed on as appropriate.
Details
panel.3dbars and panel.3dpolygon are both suitable for use as (components of) the panel.3d.cloud
argument of panel.cloud. The first one produces three dimensional bars, and the second one
draws three dimensional polygons.
Author(s)
Deepayan Sarkar [email protected]
See Also
cloud, panel.cloud
Examples
library(lattice)
Description
Reasons for Taking First Postdoctoral Appointment, by Field of Doctrate, 1997
rootogram 19
Usage
data(postdoc)
Format
The data set is avaliable as a two-way table of counts.
Source
Survey of Doctorate Recipients, 1997
References
Enhancing the Postdoctoral Experience for Scientists and Engineers: A Guide for Postdoctoral
Scholars, Advisers, Institutions, Funding Organizations, and Disciplinary Societies
http://books.nap.edu/catalog.php?record_id=9831
Examples
data(postdoc)
library(lattice)
barchart(prop.table(postdoc, margin = 1),
auto.key = TRUE, xlab = "Proportion")
Description
Displays hanging rootograms.
Usage
rootogram(x, ...)
prepanel.rootogram(x, y = table(x),
dfun = NULL,
transformation = sqrt,
hang = TRUE,
...)
20 rootogram
panel.rootogram(x, y = table(x),
dfun = NULL,
col = plot.line$col,
lty = plot.line$lty,
lwd = plot.line$lwd,
alpha = plot.line$alpha,
transformation = sqrt,
hang = TRUE,
...)
Arguments
x, y For rootogram, x is the object on which method dispatch is carried out. For
the "formula" method, x is a formula describing the form of conditioning
plot. The formula can be either of the form ~x or of the form y~x. In the first
case, x is assumed to be a vector of raw observations, and an observed frequency
distribution is computed from it. In the second case, x is assumed to be unique
values and y the corresponding frequencies. In either case, further conditioning
variables are allowed.
A similar interpretation holds for x and y in prepanel.rootogram and
panel.rootogram.
data For the "formula" method, a data frame containing values for any variables
in the formula, as well as those in groups and subset if applicable (groups
is currently ignored by the default panel function). By default the environment
where the function was called from is used.
dfun a probability mass function, to be evaluated at unique x values
prepanel, panel
panel and prepanel function used to create the display.
ylab the y-axis label; typically a character string or an expression.
col, lty, lwd, alpha
graphical parameters
transformation
a vectorized function. Relative frequencies (observed) and theoretical probabil-
ities (dfun) are transformed by this function before being plotted.
hang logical, whether lines representing observed relative freuqncies should “hang”
from the curve representing the theoretical probabilities.
... extra arguments, passed on as appropriate. Standard lattice arguments as well
as arguments to panel.rootogram can be supplied directly in the high level
rootogram call.
Details
This function implements Tukey’s hanging rootograms. Also consider the rootogram function in
the vcd package, especially if the number of unique values is small.
rootogram 21
Value
rootogram produces 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.
Author(s)
Deepayan Sarkar [email protected]
See Also
xyplot
Examples
library(lattice)
update(p[rep(1, length(lambdav))],
aspect = "xy",
panel = function(x, ...) {
panel.rootogram(x,
dfun = function(x)
dpois(x, lambda = lambdav[panel.number()]))
})
update(p[rep(1, length(lambdav))],
aspect = "xy",
prepanel = function(x, ...) {
tmp <-
lapply(lambdav,
function(lambda) {
prepanel.rootogram(x,
dfun = function(x)
dpois(x, lambda = lambda))
})
list(xlim = range(sapply(tmp, "[[", "xlim")),
ylim = range(sapply(tmp, "[[", "ylim")),
dx = do.call("c", lapply(tmp, "[[", "dx")),
dy = do.call("c", lapply(tmp, "[[", "dy")))
},
panel = function(x, ...) {
panel.rootogram(x,
22 useOuterStrips
dfun = function(x)
dpois(x, lambda = lambdav[panel.number()]))
grid::grid.text(bquote(Poisson(lambda == .(foo)),
where = list(foo = lambdav[panel.number()])),
y = 0.15,
gp = grid::gpar(cex = 1.5))
},
xlab = "",
sub = "Random sample from Poisson(50)")
Description
Tried to update a "trellis" object so that strips are only shown on the top and left boundaries
when printed, instead of in every panel as is usual. This is only meaningful when there are exactly
tow conditioning variables.
Usage
useOuterStrips(x,
strip = strip.default,
strip.left = strip.custom(horizontal = FALSE))
resizePanels(x, h = 1, w = 1)
Arguments
x An object of class "trellis".
strip, strip.left
A function, character string or logical that would be appropriate strip and
strip.left arguments respectively in a high level lattice function call (see
xyplot)
h numeric vector specifying panel heights
w numeric vector specifying of panel widths
Details
useOuterStrips modifies a "trellis" object with length(dim(x)) == 2 so that when
plotted, strips are only shown on the top and left boundaries of the panel layout, rather than on top
of every panel, as is the usual behaviour.
resizePanels modifies a "trellis" object so that when plotted, the panels have the spec-
ified relative width and height; this is only interesting when h or w are vectors with unequal
useOuterStrips 23
entries. resizePanels can be called with no arguments, in which case the currently plotted
"trellis" object (if any) is used for x, and a suitable h or w (based on the current panel layout)
is chosen so that sizes are relative to the current panel ranges in the native coordinate system. This
is only interesting when scales="free"; the resulting object, when plotted again, will have
varying panel sizes but the same number of data units per inch in all panels.
Value
An object of class "trellis"; essentially the same as x, but with certain properties modified.
Author(s)
Deepayan Sarkar
See Also
Lattice, xyplot
Examples
library(lattice)
## approximate
resizePanels(dpfrost,
h = with(state, table(reorder(state.region, Frost))))
24