Learn R Programming

latticeExtra (version 0.6-4)

panel.xblocks: Plot contiguous blocks along x axis.

Description

Plot contiguous blocks along x axis.

Usage

panel.xblocks(x, ...)

## S3 method for class 'default':
panel.xblocks(x, y, ..., height = unit(1, "npc"),
              block.y = unit(0, "npc"), vjust = 0,
              col = NULL, border = NA, name = "xblocks",
              last.step = median(diff(tail(x))))

## S3 method for class 'ts':
panel.xblocks(x, y = NULL, ...)

Arguments

x, y
In the default method, x gives the ordinates along the x axis and must be in increasing order. y gives the colour values to plot as contiguous blocks. These may be character (or factor) values (colour names or hex
...
In the default method, further arguments are graphical parameters passed on to gpar.
height
height of blocks, defaulting to the full panel height. Numeric values are interpreted as native units.
block.y
y axis position of the blocks. Numeric values are interpreted as native units.
vjust
vertical justification of the blocks relative to block.y. See grid.rect.
col
if col is specified, then all values of y that are not NA or FALSE are drawn in this colour.
border
border colour.
name
a name for the grob (grid object).
last.step
width (in native units) of the final block. Defaults to the median of the last 5 time steps (assuming steps are regular).

Details

Blocks are drawn forward in "time" from the specified x locations, up until the following value. Contiguous blocks are calculated by rle.

See Also

panel.rect, grid.rect

Examples

Run this code
## Are US presidential approval ratings linked to sunspot activity?

## 'ts' method; set block height, default justification is at bottom.
xyplot(presidents) + layer(panel.xblocks(sunspot.year > 50, height = 3))

## blocks in a light shading colour, full panel height.
xyplot(presidents) +
  layer(panel.xblocks(sunspot.year > 50, col = "#e6e6e6"), under=TRUE)

## multiple colour values given in the 'y' argument.
sscols <- cut(sunspot.year, c(50,150,Inf), labels=c("yellow","orange"))
xyplot(presidents, lwd = 2) +
  layer(panel.xblocks(time(sunspot.year), y = sscols, alpha = 0.5))

Run the code above in your browser using DataLab