Learn R Programming

inlmisc (version 0.4.3)

AddColorKey: Add Color Key to Plot

Description

This function can be used to add a color key to a plot.

Usage

AddColorKey(mai, is.categorical, breaks, col, at = NULL, labels = TRUE,
  scipen = getOption("scipen", 0L), explanation = NULL, padx = 0.2,
  log = FALSE)

Arguments

mai

'numeric'. Vector of the form c(bottom, left, top, right) which gives the margin size specified in inches (optional).

is.categorical

'logical'. If true, color-key values represent categorical data; otherwise, these data values are assumed continuous.

breaks

'numeric'. Set of finite numeric breakpoints for the colors: must have one more breakpoint than color and be in increasing order.

col

'character'. Vector of colors to be used in the plot. This argument requires breaks specification for continuous data. For continuous data there should be one less color than breaks; whereas, categorical data require a color for each category.

at

'numeric'. The points at which tick-marks and labels are to be drawn, only applicable for continuous data. The tick marks will be located at the color breaks if the length of at is greater than or equal to one minus the length of breaks. Note that tick-mark labels are omitted where they would abut or overlap previously drawn labels (labels are drawn left to right).

labels

'logical', 'character', 'expression', or 'numeric'. Can either be a logical value specifying whether (numerical) annotations are to be made at the tick marks, or a character or expression vector of labels to be placed at the tick points.

scipen

'integer'. A penalty to be applied when deciding to format numeric values in scientific or fixed notation. Positive values bias towards fixed and negative towards scientific notation: fixed notation will be preferred unless it is more than scipen digits wider. Specify NULL to format all numbers, with the exception of zero, in scientific notation.

explanation

'character'. Label that describes the data values.

padx

'numeric'. Inner padding for the left and right margins specified in inches.

log

'logical'. Whether the axis is to be logarithmic.

Value

Used for the side-effect of a color key drawn on the current graphics device.

See Also

PlotCrossSection, PlotMap

Examples

Run this code
# NOT RUN {
op <- par(mfrow = c(7, 1), omi = c(1, 1, 1, 1), mar = c(2, 3, 2, 3))
AddColorKey(is.categorical = FALSE, breaks = 0:10,
            explanation = "Example description of data variable.")
AddColorKey(is.categorical = FALSE, breaks = 0:1000, at = pretty(0:1000))
AddColorKey(is.categorical = FALSE, breaks = c(0, 1, 2, 4, 8, 16))
breaks <- c(pi * 10^(-5:5))
AddColorKey(is.categorical = FALSE, breaks = breaks, log = TRUE)
is <- as.logical(seq_along(breaks) %% 2)
AddColorKey(is.categorical = FALSE, breaks = breaks, at = breaks[is],
            scipen = NULL, log = TRUE)
AddColorKey(is.categorical = TRUE, labels = LETTERS[1:5])
AddColorKey(is.categorical = TRUE, col = GetTolColors(5, scheme = "bright"))
par(op)

# }

Run the code above in your browser using DataLab