image_scale | R Documentation |
Plots a scale in the right margin of a plot, typically an image plot.
image_scale(z, col, x, y = NULL, size = NULL, digits = 2, labels = c("breaks", "ranges"),
cex.legend=1)
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 |
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 |
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 |
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 |
None, used for its plotting side effect.
This function appears in the book text as image.scale
; renamed here to avoid confusion with generic image
functions.
Andy Royle.
Royle, J.A., Chandler, R.B., Sollmann, R., & Gardner, B. (2014) Spatial capture-recapture, Elsevier.
# 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.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.