https://github.com/cran/fields
Tip revision: 92636eaee56714c89c7b7e7cdc52e0c77aeb79b3 authored by Doug Nychka on 07 February 2005, 00:00:00 UTC
version 2.3
version 2.3
Tip revision: 92636ea
colorbar.plot.R
"colorbar.plot" <-
function (x,y,strip, strip.width = 0.1, strip.length=4*strip.width,
zrange=NULL, adj.x=.5,adj.y=.5,col=tim.colors(256),horizontal=TRUE,...)
{
# coerce to be one column matrix if it is a vector
if( !is.matrix( strip)) { strip<- matrix( c( strip), ncol=1)}
m<- nrow( strip)
n<- ncol(strip)
# find common range across strips if not specified
if( is.null(zrange)) {
zrange<- matrix( range(c( strip),na.rm=TRUE), nrow=n, ncol=2, byrow=TRUE) }
# see help( par) for background on graphical settings
ucord <- par()$usr
pin <- par()$pin
if( horizontal){
dy<- strip.width*(ucord[4] - ucord[3])
dx<- strip.length* pin[2]*(ucord[2] - ucord[1])/(pin[1])}
else{
dx<- strip.width*(ucord[2] - ucord[1])
dy<- strip.length* pin[1]*(ucord[4] - ucord[3])/(pin[2])}
#
# dx and dy should have the correct ratio given different different scales
# and also different aspects to the plot window
#
n<- ncol( strip)
m<- nrow( strip)
# create grids in x and y for strip(s) based on the users
# coordinates of the plot and th positioning argument (adj)
if( horizontal) {
xs<- seq(0, dx,, m+1) +x - adj.x*dx
ys<- seq(0, dy,,n+1) +y - adj.y*dy }
else{
xs<- seq(0, dx,, n+1) +x - adj.x*dx
ys<- seq(0, dy,,m+1) +y - adj.y*dy }
#
# plot image row by row to allow for different zlim's
# see image.add for a fields function that just plots the whole image at
# once.
for( k in 1:n){
if( horizontal){
image( xs, c(ys[k],ys[k+1]), cbind(strip[,k]),
zlim= zrange[k,],add=TRUE, col=col,...)}
else{
image( c(xs[k],xs[k+1]), ys, rbind(strip[,k]),
zlim= zrange[k,],add=TRUE, col=col,...)}
}
}