Learn R Programming

aqfig (version 0.9)

vertical.image.legend: 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

vertical.image.legend(zlim, col)

Value

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

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.

Author

Jenise Swall

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. The user should finish making the main portion of the plot before adding the legend; i.e., the user should add the legend last. This function alters the par settings to draw the legend. Upon exit, it resets them back to what they were before the function call.

See Also

image.plot

Examples

Run this code
# 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)

Run the code above in your browser using DataLab