Skip to content

persp( ) Question

2 messages · Brahm, David, Martin Maechler

#
Greg,

Assign the output of "persp" to a variable "pmat":
R> pmat <- persp(X.grid, Y.grid, pred.loess1, theta=0, phi=12)

Now you can add points to your plot with the usual "points" command.
But you have to translate your 3D coordinates (x,y,z) into 2D
coordinates for "points" to understand, and that's what "trans3d" does:

R> points(trans3d(x,y,z, pmat), col="red")

You supply the (x,y,z) values, of course.  It's a mystery to me why
"trans3d" is not included in the graphics package (where "persp" lives).
HTH.

-- David Brahm (brahm at alum.mit.edu)
7 days later
#
DavidB> Greg, Assign the output of "persp" to a variable
    DavidB> "pmat":
    R> pmat <- persp(X.grid, Y.grid, pred.loess1, theta=0,
    R> phi=12)

    DavidB> Now you can add points to your plot with the usual
    DavidB> "points" command.  But you have to translate your 3D
    DavidB> coordinates (x,y,z) into 2D coordinates for "points"
    DavidB> to understand, and that's what "trans3d" does:

    R> points(trans3d(x,y,z, pmat), col="red")

    DavidB> You supply the (x,y,z) values, of course.  It's a
    DavidB> mystery to me why "trans3d" is not included in the
    DavidB> graphics package (where "persp" lives).  HTH.

Yes, I had similar thoughts many weeks ago, and already then
prepared to add to trans3d().  Will do this now (for R 2.2.0).

Martin