image_scale {AHMbook}R Documentation

Helper function to draw scale for image

Description

Plots a scale in the right margin of a plot, typically an image plot.

Usage

image_scale(z, col, x, y = NULL, size = NULL, digits = 2, labels = c("breaks", "ranges"),
      cex.legend=1)

Arguments

z

a vector of at least 2 numbers which define the range of values for which colors should be plotted; this should be the same as the value of zlim passed to image or, if that was not used, the values passed as z.

col

a vector of colors, use the same as in the image

x

the x coordinate of the left edge of the scale bar; or a list with components x and y, each of length 2, giving the x and y coordinates of the edges of the scale bar.

y

the y coordinate of the bottom edge of the scale bar, ignored if x is a list

size

the size of the boxes making up the scale bar, a length 2 vector with the width and height, or a scalar, in which case width = height; ignored if x is a list

digits

the number of decimal places to display

labels

if "breaks", the dividing lines in the scale bar are labeled, if "ranges", each box is labeled with its range; may be abbreviated

cex.legend

the magnification to be used for axis annotation

Value

None, used for its plotting side effect.

Note

This function appears in the book text as image.scale; renamed here to avoid confusion with generic image functions.

Author(s)

Andy Royle.

References

Royle, J.A., Chandler, R.B., Sollmann, R., & Gardner, B. (2014) Spatial capture-recapture, Elsevier.

Examples

# uses the built-in volcano data set
require(grDevices) # for colours
require(graphics)
par(mar = c(3,3,3,6))  # make the right margin wide enough
image(t(volcano)[ncol(volcano):1,], col=terrain.colors(12))
image_scale(volcano, col=terrain.colors(12))
# Try placing the scale bar on the left
par(mar = c(3,8,3,1))  # make the left margin wide enough
image(t(volcano)[ncol(volcano):1,], col=terrain.colors(12))
image_scale(volcano, col=terrain.colors(12), x= -0.28, digits=0, cex.legend=1.2)
# Trial and error needed to get the x value right.

[Package AHMbook version 0.2.9 Index]