legend.scale: Color scale legend

Description Usage Arguments Details References See Also Examples

View source: R/legend.scale.R

Description

legend.scale plots a color gradient with an associated quantitative scale.

Usage

1
2
legend.scale(zlim, col = viridisLite::viridis(12), horizontal = TRUE,
  breaks, axis.args)

Arguments

zlim

A two-dimensional vector containing the minimum and maximum quantitative limits, respectively, for the color scale.

col

A vector of colors used for the color scale. Typically, this is a gradient of colors. The default is the 12 colors generated by viridisLite::viridis(12).

horizontal

A logical value indicating whether the legend should extend horizontally (TRUE) or vertically (FALSE). The default is TRUE.

breaks

The sequence of values defining the partition of zlim. The length should be one more than then number of colors. If not specified, then equidistant breaks are used.

axis.args

A list of named elements corresponding to the arguments of the axis function. This is used to modify the appearance of the scale of the legend. See Examples.

Details

The length of the col vector indicates the number of partitions for the quantitative range.

References

The code for this function is derived from the internals of the image.plot function written by Doug Nychka and from the image.scale function written by Marc Taylor and discussed at http://menugget.blogspot.com/2013/12/new-version-of-imagescale-function.html.

See Also

image, image.plot, axis

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# default horizontal scale
legend.scale(c(0, 1))

# default vertical scale
legend.scale(c(0, 1), horizontal = FALSE)

# different color scheme with 24 colors
legend.scale(c(0, 1), col = cm.colors(24))

# irregular color breaks
legend.scale(c(0, 1), col = heat.colors(4), 
             breaks = c(0, 0.5, 0.75, 0.875, 1))

# irregular color breaks with modified ticks and vertical 
# orientation of labels
legend.scale(c(0, 1), col = heat.colors(4),
             breaks = c(0, 0.5, 0.75, 0.875, 1),
             axis.args = list(at = c(0, 0.5, 0.75, 0.875, 1), las = 2))

# change size of axis labels
legend.scale(c(0, 1), axis.args = list(cex.axis = 2))

# change color of axis labels and ticks
blue.axes <- list(col.axis = "blue", col.ticks = "blue")
legend.scale(c(0, 1), axis.args = blue.axes)

# log base 10 values with colors labeled on original scale
options(scipen = 2)
log.axis <- list(at = 0:6, labels = 10^(0:6), las = 2)
legend.scale(c(0, 6), col = heat.colors(6), axis.args = log.axis)

autoimage documentation built on May 30, 2017, 12:53 a.m.

Search within the autoimage package
Search all R packages, documentation and source code