https://github.com/cran/fields
Raw File
Tip revision: beb6c9118b4f355fc630943f00274a7df8714fe1 authored by Doug Nychka on 26 April 2007, 00:00:00 UTC
version 3.5
Tip revision: beb6c91
add.image.R
"add.image" <-
function(xpos,ypos,z,adj.x=.5,adj.y=.5,image.width=.15, 
image.height= NULL, col=tim.colors(256), ...) 
{
   m<- nrow( z)
   n<- ncol(z)

   ucord <- par()$usr
   pin <- par()$pin

# if height is missing scale according to width assuming pixels are 
# square. 

   if( is.null( image.height)){
      image.height<- (n/m)*image.width}

# find grid spacing in user coordinates. 
   dy<- image.width*(ucord[4] - ucord[3])
   dx<- image.height* pin[2]*(ucord[2] - ucord[1])/(pin[1])


#
# dx and dy should have the correct ratio given different different scales 
# and also different aspects to the plot window 
#

# find grid to put image in right place. 
    xs<- seq(0, dx,, m+1) +xpos - adj.x*dx
    ys<- seq(0, dy,,n+1) +ypos - adj.y*dy 

  image( xs, ys, z,add=TRUE, col=col,...)
}

back to top