Add a Legend to an Image Plot

DESCRIPTION:
Adds a legend to a current image plot. The location, size, orientation, and (approximate) grade intervals can be specified. If not specified, you will be prompted to input location and/or size.

USAGE:
image.legend(zmat, x=<<see below>>, y=<<see below>>, size=c(1, 1),
             horizontal=T, nint=50)

REQUIRED ARGUMENTS:
zmat:
numeric vector, or a list containing a numeric component named z. This should be the matrix that is represented in the image.
Missing values (NA) are allowed.

OPTIONAL ARGUMENTS:
x,y:
location of the rectangle in which to put the legend scale, in user coordinates. If x and y are of length 1, they determine the upper left corner of the legend scale; if they are vectors of length 2, they specify opposite corners of the legend scale. A list containing x and y values may be supplied instead (as x). If x is missing, a call to the locator function is made to determine the placement (and size, see below).
size:
vector containing the width and height of the legend scale, in (approximate) inches. If size and x are both missing, you are required to enter two points on the existing plot (with locator) to specify the opposite corners of the legend scale.
horizontal:
logical flag: if TRUE, the orientation of the image legend is horizontal.
nint:
approximate number of intervals shown on the image legend. The higher the value, the more gradations of color (or grayscale). The upper limit is determined by how many image colors (or grays) are supported by the device in its current state.

Graphical parameters may also be supplied as arguments to this function (see par).


SIDE EFFECTS:
a box is drawn at the specified coordinates, and a color, grayscale or halftone scale (depending on the graphics device) is placed inside. Values corresponding to the colors or grays in this scale are indicated on one margin of the box.

DETAILS:
The size specified includes the image scale and the surrounding box only; the tick marks and axis labels are outside this region.

SEE ALSO:
image , legend , locator , subplot , par .

EXAMPLES:
# put up an image plot, then put up a horizontal legend

i <- interp(ozone.xy$x, ozone.xy$y, ozone.median) image(i) image.legend(i)

# add a vertical legend with a specific location rx <- range(ozone.xy$x) ry <- range(ozone.xy$y) image(i) # draw boundaries in the background color usa(xlim=rx, ylim=ry, add=T, col=0) # draw dashed lines to ensure the lines are visible everywhere usa(xlim=rx, ylim=ry, add=T, lty=2) image.legend(i$z, x=-74.7, y=43.3, size=c(.5, 1.5), hor=F) title(main="Median Ozone Concentrations in the North East")