SCM Repository

[latticeextra] View of /pkg/man/panel.xblocks.Rd
ViewVC logotype

View of /pkg/man/panel.xblocks.Rd

Parent Directory Parent Directory | Revision Log Revision Log

Revision 194 - (download) (as text) (annotate)
Fri Jan 1 11:17:13 2016 UTC (3 years, 1 month ago) by deepayan
File size: 4553 byte(s)
cleanup based on feedback from R CMD check
  Plot contiguous blocks along x axis.
  Plot contiguous blocks along x axis. A typical use would be to
  highlight events or periods of missing data.
panel.xblocks(x, ...)

\method{panel.xblocks}{default}(x, y, ..., col = NULL, border = NA, 
              height = unit(1, "npc"),
              block.y = unit(0, "npc"), vjust = 0,
              name = "xblocks", gaps = FALSE,
              last.step = median(diff(tail(x))))

\method{panel.xblocks}{ts}(x, y = x, ...)
\method{panel.xblocks}{zoo}(x, y = x, ...)
  \item{x, y}{
    In the default method, \code{x} gives the ordinates along the x axis and
    must be in increasing order. \code{y} gives the color values to plot as
    contiguous blocks. If \code{y} is numeric, data coverage is plotted,
    by converting it into a logical (\code{!}). Finally, if
    \code{y} is a function, it is applied to \code{x} (\code{time(x)} in
    the time series methods). 
    If \code{y} has character (or factor) values, these are interpreted
    as colors -- and should therefore be color names or hex
    codes. Missing values in \code{y} are not plotted.  The default
    color is taken from the current theme:
    \code{trellis.par.get("plot.line")$col}. If \code{col} is given,
    this over-rides the block colors.

    The \code{ts} and \code{zoo} methods plot the \code{y} values
    against the time index \code{time(x)}. 
    In the default method, further arguments are graphical parameters
    passed on to \code{\link{gpar}}.
    if \code{col} is specified, it determines the colors of the blocks
    defined by \code{y}. If multiple colors are specified they will be
    repeated to cover the total number of blocks.
    border color.
    height of blocks, defaulting to the full panel height. Numeric
    values are interpreted as native units.
    y axis position of the blocks. Numeric values are interpreted as
    native units.
    vertical justification of the blocks relative to \code{block.y}. See
    a name for the grob (\pkg{grid} object).
    Use \code{panel.xblocks(time(z),} instead.
    width (in native units) of the final block. Defaults to the median of
    the last 5 time steps (assuming steps are regular).
  Blocks are drawn forward in "time" from the specified x locations,
  up until the following value. Contiguous blocks are calculated using
  Felix Andrews \email{}
## Example of highlighting peaks in a time series.
flow <- ts(filter(rlnorm(200, mean = 1), 0.8, method = "r"))

## using an explicit panel function
xyplot(flow, panel = function(x, y, ...) {
  panel.xblocks(x, y > mean(y), col = "lightgray")
  panel.xyplot(x, y, ...)
## using layers; this is the `ts` method because `>` keeps it as ts.
xyplot(flow) +
  layer_(panel.xblocks(flow > mean(flow), col = "lightgray"))

## Example of alternating colors, here showing calendar months
flowdates <- as.Date("2000-01-01") + as.numeric(time(flow))
xyplot(flow ~ flowdates, type = "l") +
  layer_(panel.xblocks(x, months,
         col = c("lightgray", "#e6e6e6"), border = "darkgray"))

## highlight values above and below thresholds.
## blue, gray, red colors:
bgr <- hcl(c(0, 0, 260), c = c(100, 0, 100), l = c(90, 90, 90))
dflow <- cut(flow, c(0,15,30,Inf), labels = bgr)
xyplot(flow) + layer_(panel.xblocks(time(flow), dflow))

## Example of highlighting gaps (NAs) in time series.
## set up example data
z <- ts(cbind(A = 0:5, B = c(6:7, NA, NA, 10:11), C = c(NA, 13:17)))

## show data coverage only (highlighting gaps)
xyplot(z, panel = panel.xblocks,
       scales = list(y = list(draw = FALSE)))

## draw gaps in darkgray
xyplot(z, type = c("p","s")) +
  layer_(panel.xblocks(x,, col = "darkgray"))

## Example of overlaying blocks from a different series.
## Are US presidential approval ratings linked to sunspot activity?
## Set block height, default justification is along the bottom.
xyplot(presidents) + layer(panel.xblocks(sunspot.year > 50, height = 2))
\keyword{ dplot }
ViewVC Help
Powered by ViewVC 1.0.0  
Thanks to:
Vienna University of Economics and Business University of Wisconsin - Madison Powered By FusionForge