image
function with some automatic
placement of a legend. This is done by splitting the plotting region
into two parts. Putting the image in one and the legend in the
other.This function and help file are copied from the fields package.
image_plot(..., add = FALSE, nlevel = 64, legend.shrink = 0.9, legend.width = 0.05, graphics.reset = FALSE, horizontal = FALSE, offset = 2 * legend.width, bigplot = NULL, smallplot = NULL, legend.only = FALSE, col = topo.colors(nlevel))
image
function.
because this function may change the size of the plotting
region. (See details below)
The strategy is simple, divide the plotting region into two smaller regions. The image goes in one and the legend in the other. This way there is always room for the legend. Some adjustments are made to this rule by not shrinking the image plot if there is already room for the legend strip and also sticking the legend strip close to the image plot. Also, one can specify the plot regions explicitly by bigplot and small plot if the default choices do not work. There may be problems with small plotting regions in fitting both of these plot and one may have to change the default character sizes or margins to make things fit.
By keeping the zlim argument the same across images one can generate
the same color scale. (See image
help file) One useful technique for a
panel of images is to just draw the first with image.plot to get a legend
and just use image for subsequent plots. Also keep in mind one can just
add a legend to an existing plot without changing plotting parameters.
Usually a square plot (pty="s") done in a rectangular plot region will
have room for the legend with any adjustments stuck to the right side.
image
x<- 1:10
y<- 1:15
z<- outer( x,y,"+")
image_plot(x,y,z)
# now add some points on diagonal
points( 5:10, 5:10)
#
#fat (5% of figure) and short (50% of figure) legend strip on the bottom
image_plot( x,y,z,legend.width=.05, legend.shrink=.5, horizontal=TRUE)
# add a legend on the bottom but first change margin for some room
par( mar=c(10,5,5,5))
image( x,y,z)
image_plot( zlim=c(0,25), legend.only=TRUE, horizontal=TRUE)
Run the code above in your browser using DataLab