Hi Greg,
I've solved the problem by adding the drop-lines from each point to the
surface manually, this is only a pain because s-plus doesn't seem to have a
built-in bivariate interpolation routine. Unfortunately this doesn't allow
for nice 32-colour surface but in that case I think the points and drop
lines may have been less clear (there is also the possibility that someone
may want to print this in black & white). Here's the script in case anyone
else has the same problem.
All the best,
Mike.
bivariateInterp<-function(x,y,grid) # interpolate grid at point (x,y)
{
i <- 1
while(x > grid$x[i])
{
i <- i+1
}
j <- 1
while(y > grid$y[j])
{
j <- j+1
}
x1 <- grid$x[i]
x2 <- grid$x[i+1]
y1 <- grid$y[i]
y2 <- grid$y[i+1]
z1 <- grid$z[i,i]
z2 <- grid$z[i+1,i]
z3 <- grid$z[i+1,i+1]
z4 <- grid$z[i,i+1]
t <- (x - x1) / (x2 - x1)
u <- (y - y1) / (y2 - y1)
return ((1.0 - t) * (1.0 - u) * z1 + t * (1.0 - u) * z2 + t * u * z3 +
(1.0 - t) * u * z4)
}
MF <-
read.table("../Research/MarketModels/2FComparisonPaper/Plots/MFL29T15.txt",header=T)
SLM <-
read.table("../Research/MarketModels/2FComparisonPaper/Plots/2FSLMT15.txt",header=T)
MF.gridSize <- 20
MF.grid <-
interp(MF$u,MF$v,MF$L29,xo=seq(-2,2,length=MF.gridSize),yo=seq(-50,50,length=MF.gridSize))
graphsheet(width=10, height=10)
MF.plot <- persp(MF.grid,xlab="u",ylab="v",zlab="log(LIBOR)")
SLM.line.start <- perspp(SLM$u,SLM$v,SLM$L29,MF.plot)
points(SLM.line.start, cex=0.75)
for(i in 1:length(SLM$L15)) SLM$intersect[[i]] <-
bivariateInterp(SLM$u[i],SLM$v[i],MF.grid)
SLM.line.end <- perspp(SLM$u,SLM$v,SLM$intersect,MF.plot)
segments(x1=SLM.line.start$x,y1=SLM.line.start$y,x2=SLM.line.end$x,y2=SLM.line.end$y)
----- Original Message -----
From: "Greg Snow" <greg.snow@ihc.com>
To: <M.N.Bennett@warwick.ac.uk>
Sent: Wednesday, November 10, 2004 5:32 PM
Subject: Re: [S] Fw: Graphing points with drop lines to a 3D surface
I don't think that the GUI is going to work for you then (at least not
without a lot of kludging).
The interp function will interpolate the surface for you.
If you still want color draped surfaces, and flexibility, you might
need to use R instead. You will still use the R version of persp, but
look at the help file for persp to see how to add points (there is no
perspp function, but the examples in the help on persp shows how to do
the same thing). The interp function for R is in the akima package (you
might actually want interpp) a couple of other packages also include
interpolation functions, I don't know if they are any better or not.
Greg Snow, Ph.D.
Statistical Data Center
greg.snow@ihc.com
(801) 408-8111
"Michael Bennett" <M.N.Bennett@warwick.ac.uk> 11/10/04 09:38AM >>>
Thanks for your response, Greg.
I've probably not made it clear exactly what I'm after: I would like
the
drop-lines to be drawn between the points and the surface (not down to
zero). Therefore I don't think the gui is flexible enough (only appears
to
allow me to draw drop-down lines to zero).
The persp function may be a solution with a lot of manual effort: it
may be
possible to interpolate the surface to find where each drop line hits
then
use perspp (after constructing the original surface with persp) to add
lines
one by one, but this is not straightforward - is there no other way
(esp.
one that allows me to plot nice 32-colour plots)?
All the best,
Mike.
----- Original Message -----
From: "Greg Snow" <greg.snow@ihc.com>
To: <s-news@lists.biostat.wustl.edu>; <M.N.Bennett@warwick.ac.uk>
Sent: Wednesday, November 10, 2004 3:30 PM
Subject: Re: [S] Fw: Graphing points with drop lines to a 3D surface
>From the command line:
Look at the perspp (note 2 p's at the end) function. With the 3d
coordinates, perspp will transform them to 2d coordinates that you
can
use with segments, points, or lines to add things to a perspective
plot
(remember to save the output of persp). Note that your added lines
will
be on top of the perspective plot without anything like hidden line
removal.
From the GUI:
Create the surface plot, click the mouse between the surface and the
axes so that 3 green circles and a green triangle appear, select the
data for the points and drop lines then shift-click on the plots3d
button for "drop line scatter"
hope this helps,
Greg Snow, Ph.D.
Statistical Data Center
greg.snow@ihc.com
(801) 408-8111
"Michael Bennett" <M.N.Bennett@warwick.ac.uk> 11/10/04 06:37AM
Hi, I'm hoping someone may be able to help me with a problem I'm
having
with graphing some results in s-plus: I'm trying to construct a plot
where I need to draw a 3D wireframe surface of values of a response
that
I have computed over a regular (this is OK) then add some points to
the
graph with "drop-lines" to the surface to indicate how far the
points
are from the surface. How can I achieve this last step?
Mike Bennett
--------------------------------------------------------------------
This message was distributed by s-news@lists.biostat.wustl.edu. To
unsubscribe send e-mail to s-news-request@lists.biostat.wustl.edu
with
the BODY of the message: unsubscribe s-news
|