[6492] in s-news-athena
modified image function
daemon@ATHENA.MIT.EDU (Pierre Kleiber)
Thu Feb 23 00:00:19 1995
Date: Tue, 21 Feb 95 15:28:09 PST
From: pierre@pooh.UCSD.EDU (Pierre Kleiber)
To: s-news@utstat.toronto.edu
Reply-To: pkleiber@ucsd.edu
Last week I asked if anyone has produced a modified form of the
image() function that could color a specified polygon in each
cell of an image plot rather than the whole cell. Not having had
any responses, I put together the following first stab
in which the vertices of the polygon are specified by the vectors,
sax, and say, in units such that (0,0) is the lower, left corner
of each cell and (1,1) is the upper right corner:
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)
}
}
}
There are several obvious improvements easily within my
capability that would make this function act more like image(),
but the main problem is speed (or lack thereof). Dealing with
that is beyond me in the absence of source code for image()
(and maybe me even with said souce code). I'd like advice from
some of the S gurus about whether it would be feasable for me
to get ahold of the source code and add the capability that I'm
after, or whether I should beg the good folks at ATT and StatSci
and wait for it in some revision down the road.
By the way, the reason for all this is to be able to juxtapose
image() images on the same plot.
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
-----------------------------------------------------------------