Skip to Content

segplot {latticeExtra}

Plot segments using the Trellis framework
Package: 
latticeExtra
Version: 
0.6-26

Description

This function can be used to systematically draw segments using a formula interface to produce Trellis displays using the lattice package. Segments can be drawn either as lines or bars, and can be color coded by the value of a covariate, with a suitable legend.

Usage

segplot(x, data, ...)
 
## S3 method for class 'formula':
segplot((x, data,
        level = NULL, centers = NULL,
        prepanel = prepanel.segplot,
        panel = panel.segplot,
        xlab = NULL, ylab = NULL,
        horizontal = TRUE,
        ...,
        at, cuts = 30, colorkey = !is.null(level)))

Arguments

x
Argument on which argument dispatch is carried out. For the "formula" method, a formula of the form y ~ x1 + x2 (with further conditioning variables appended if necessary). The terms in the formula must all be vectors of the same length. Each element causes a line segment or rectangle to be drawn, with the vertical location determined by y and horizontal endpoints determined by x1 and x2.
data
An optional data frame, list or environment where variables in the formula, as well as level, will be evaluated.
level
An optional covariate that determines color coding of the segments
centers
optional vector of ‘centers’ of the segments. If specified, points will be plotted at these y-locations.
prepanel
function determining range of the data rectangle from data to be used in a panel.
panel
function to render the graphic given the data. This is the function that actually implements the display.
xlab, ylab
Labels for the axes. By default both are missing.
horizontal
logical, whether the segments are to be drawn horizontally (the default) or vertically. This essentially swaps the role of the x- and y-axes in each panel.
...
further arguments. Arguments to levelplot as well as to the default panel function panel.segplot can be supplied directly to segplot.
colorkey
logical indicating whether a legend showing association of segment colors to values of level should be shown, or a list to control details of such a color key. See details below.
at, cuts
at specifies the values of level where the color code changes. If at is missing, it defaults to cuts equispaced locations spanning the range of levels

Details

The levelplot function from the lattice package is used to internally to implement this function. In particular, the colorkey mechanism is used as it is, and documentation for levelplot should be consulted to learn how to fine tune it.

Values

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.

Note

Currently only horizontal segments are supported. Vertical segments can be obtained by modifying the prepanel and panel functions suitably.

See Also

Lattice, panel.segplot, levelplot, xyplot

Examples

segplot(factor(1:10) ~ rnorm(10) + rnorm(10), level = runif(10))
 
data(USCancerRates)
 
segplot(reorder(factor(county), rate.male) ~ LCL95.male + UCL95.male,
        data = subset(USCancerRates, state == "Washington"))
 
segplot(reorder(factor(county), rate.male) ~ LCL95.male + UCL95.male,
        data = subset(USCancerRates, state == "Washington"),
        draw.bands = FALSE, centers = rate.male)
 
segplot(reorder(factor(county), rate.male) ~ LCL95.male + UCL95.male,
        data = subset(USCancerRates, state == "Washington"),
        level = rate.female, col.regions = terrain.colors)
 
segplot(reorder(factor(county), rate.male) ~ LCL95.male + UCL95.male,
        data = subset(USCancerRates, state == "Washington"),
        draw.bands = FALSE, centers = rate.male, 
        segments.fun = panel.arrows, ends = "both", 
        angle = 90, length = 1, unit = "mm")

Author(s)

Deepayan Sarkar deepayan.sarkar@r-project.org

Documentation reproduced from package latticeExtra, version 0.6-26. License: GPL (>= 2)