# [R] 3d scatter plot with drop line

Thu Nov 18 23:35:38 CET 2004

```Very nice!
I noticed that you wrote the function to drop points to any surface.
Is it possible to add the surface to the plot as a translucent surface,
so the points and drop lines still show?

David L. Reiner

-----Original Message-----
From: Robin Hankin [mailto:rksh at soc.soton.ac.uk]
Sent: Thursday, November 18, 2004 3:39 AM
To: joel30000 at gmail.com
Cc: r-help at stat.math.ethz.ch
Subject: Fwd: Re: [R] 3d scatter plot with drop line

Hi

try this:

p3dpairs <- function(x,x1,
xlim=NULL,ylim=NULL,zlim=NULL,col=par("col"), pch=par("pch"),
cex=par("cex"), ...){
if(is.matrix(x)){
z <- x[,3]
y <- x[,2]
x <- x[,1]
}

if(is.matrix(x1)){
z1 <- x1[,3]
y1 <- x1[,2]
x1 <- x1[,1]
}

if(missing(zlim)) {
z.grid <- matrix(range(z),2,2)
} else {
z.grid <- matrix(zlim,2,2)
}

if(missing(xlim)){ xlim <- range(x) }
if(missing(ylim)){ ylim <- range(y) }

persp(xlim, ylim, z.grid, col = NA, border=NA, ...) -> res

trans3d <- function(x,y,z, pmat) {
tr <- cbind(x,y,z,1) %*% pmat
list(x = tr[,1]/tr[,4], y= tr[,2]/tr[,4])
}

out <- trans3d(x,y,z,pm=res)
out1 <- trans3d(x1,y1,z1,pm=res)
points(out, col=col, pch=pch, cex=cex, ...)

for(i in 1:length(out\$x)){
lines(c(out\$x[i],out1\$x[i]),c(out\$y[i],out1\$y[i]), col="gray", ...)
}
return(invisible(out))
}

then

a <- matrix(rnorm(60),20,3)
b <- a
b[,3] <- 0
p3dpairs(a,b)

gives you a good approximation to what you want

HTH

rksh
>
>
>>This is a follow up to my question from yesterday. I want to do in R
>>what is called a "3d scatter plot with drop lines" in S-PLUS.
>>
>>Basically, it's a 3dscatterplot with lines connecting the x-y grid to
>>the z points.
>>The lines give a better perspective on the shape of the data surface.
>>
>>How to?
>>
>>Joel Bremson
>>UC Davis Statistics
>>
>>______________________________________________
>>R-help at stat.math.ethz.ch mailing list
>>https://stat.ethz.ch/mailman/listinfo/r-help
http://www.R-project.org/posting-guide.html
>
>
>--
>
>Robin Hankin
>Uncertainty Analyst
>Southampton Oceanography Centre
>SO14 3ZH
>tel +44(0)23-8059-7743
>initialDOTsurname at soc.soton.ac.uk (edit in obvious way; spam
precaution)

--
Robin Hankin
Uncertainty Analyst
Southampton Oceanography Centre
SO14 3ZH
tel +44(0)23-8059-7743
initialDOTsurname at soc.soton.ac.uk (edit in obvious way; spam precaution)
[[alternative HTML version deleted]]

______________________________________________
R-help at stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help