I’ve been using a modified version of image.plot (fields package) that I found on the R help listserv to plot a legend. https://stat.ethz.ch/pipermail/r-help/2008-June/164700.html
library(fields)
imp <- `body<-`(image.plot,value=`[[<-`(body(image.plot),28,
quote({par(big.par)
par(plt = big.par$plt, xpd = TRUE)
par(mfg = mfg.save, new = FALSE)
invisible()})))
The following is an example dataset
m <- matrix(1:15,ncol=3)
par(mar=c(5,5,5,3))
imp(m,axes=FALSE)
box()
axis(1,axTicks(1),lab=letters[1:length(axTicks(1))])
However, I’d like to add a title (preferably aligned vertically) to the legend to specify the units. I don’t know where in the body(image.plot) I can make this modification or how to specify this when I call imp. When I try to create a larger layout in which to place the image.plot I receive the error that the figure is too large for the layout margins.
Any help would be appreciated.
I have since modified my code so that I can plot a (3,2) panel with separate commands to just plot the legend horizontally along the bottom. However, I'd like to have two legends, one under each column of plots but the legend only plots in the lower right. I know I'm plotting the legend in the white space I set prior to plotting the (3,2) panel.
par( oma=c(8,2,1,1))
set.panel(3,2)
But I'd like to know how to move about in that space that I made for the legend. Specifying side doesn't seem to work, nor does changing the oma values.
par( oma=c(2,0,2,0))
image.plot(x,y,z, legend.only=TRUE, horizontal=TRUE, legend.mar=5,
legend.shrink = 0.8)
mtext(line=1, side=1, "cms", outer=F)