Put color bar legend in the right plot margin.

Description

Put color bar legend in the right-hand side margin of an existing plot.

Usage

1

Arguments

zlim

Gives the range of z values to which the colors specified in col are assigned.

col

Gives the range of colors to use. To keep multiple plots consistent in terms of the colors assigned to various values, keep zlim and col the same for each of the plots and the legend.

Details

This function works best when there is only one plot on the device, in which case the margin space is straightforward (no confusion between oma/omi and mar/mai, etc. Originially, this function also assumed that the user had already finished making the main portion of the plot before adding the legend; i.e., the user should add the legend last. While the author believes that this issue has been resolved, the author recommends that the user avoid changing the main plot after using this legend command. This function alters the par settings to draw the legend, and trying to reset them properly is not straightforward.

Value

Puts vertical color bar legend to the right of the plot.

Note

As noted in the help for image.plot in the fields package, putting a legend on a plot is harder than it might seem. The user may have to experiment with this function a bit to get it to work well for a specific application. The user may also want to try the previously mentioned image.plot function in the fields package. (To just add the legend using image.plot, use “legend.only=TRUE”.)

Author(s)

Jenise Swall

See Also

image.plot

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
## Plot ozone at each location using colors from rainbow.colors
## and differently-sized points.  Add a legend using function
## vertical.image.legend (included in this package).
data(ozone1)
col.rng <- rev(rainbow(n=10, start=0, end=4/6))
z.rng <- c(40, 90)
plot3d.points(x=ozone1$longitude, y=ozone1$latitude, z=ozone1$daily.max,
              xlab="longitude", ylab="latitude", zlim=z.rng, col=col.rng,
              cex.min=0.5, cex.max=1.5)
## To verify, label the points with their concentrations.
text(ozone1$longitude, ozone1$latitude+0.15, ozone1$daily.max, cex=0.7)
## If maps package is available, put on state lines.
if (require("maps"))  map("state", add=TRUE, col="lightgray")
## Put on legend.
vertical.image.legend(col=col.rng, zlim=z.rng)