[6489] in s-news-athena

home help back first fref pref prev next nref lref last post

modified image() function

daemon@ATHENA.MIT.EDU (Pierre Kleiber)
Wed Feb 22 18:10:42 1995

Date: Wed, 22 Feb 95 14:41:54 PST
From: pierre@pooh.UCSD.EDU (Pierre Kleiber)
To: s-news@utstat.toronto.edu
Cc: pierre@pooh.UCSD.EDU
Reply-To: pkleiber@UCSD.EDU

I think I posted an approximation of the following yesterday,
but it seems to have evaporated.  Apologies for any duplicates:

Last week I asked S-news whether anyone might have implemented a
modification of image() such that it would color a specified
subarea (e.g. a polygon) within each cell of the image() plot.
In absence of any replies, I put together the following first
stab at it:

polyimage <- function(x, y, z, zlim=range(z), sax=c(0,0,1,1), say=c(0,1,1,0))
{
  cscale <- .999*nrow(xgetrgb("polygons"))/(zlim[2]-zlim[1])
  for(i in 1:(length(x)-1)) {
    for(j in 1:(length(y)-1)) {
      color <- floor((z[i,j]-zlim[1])*cscale)+1
      xp <- x[i] + (x[i+1]- x[i])*sax
      yp <- y[j] + (y[j+1]- y[j])*say
      polygon(xp,yp,border=F,col=color)
    }
  }
}

This works, although it uses the polygon colors rather than the
image colors.  There are several obvious improvements, well
within my capabilities, that, aside from the polygon feature,
would make it act more like image().  It's great problem, however,
is lack of speed, and I am stymied at doing anything about that.
I suppose the best strategy would be to modify the image() source code,
which I don't have access to.  I'd like advice from any of the S
gurus out there as to whether it's feasible to get ahold of the 
image() source code and conduct such a project, or whether I should
just beg the folks at StatSci or ATT in hopes that the modification
I'm seeking might appear in a new revision somewhere down the road.

Cheers, 
------------------------------------------------------------------
Pierre Kleiber, Ph.D., Fishery Scientist  Email: pkleiber@ucsd.edu
National Marine Fisheries Service           Tel: 619 546 7076
Box 271, La Jolla, CA 92037-1508            Fax: 619 546 7003
-----------------------------------------------------------------

home help back first fref pref prev next nref lref last post