Greetings,
I have data points defined by x,y,z co-ordinates and x,y,z standard
deviations. I wish to draw 3D ellipses [perhaps using either cloud or
persp]. I sent a request to the discussion group and Bill Venables
kindly
suggested using cloud. Matlab has a very nice simple routine [surf] that
takes data and makes a nice sphere [dim(x)=dim(y)=dim(z)]. I have tried
to convert their code to splus, but the x,y,z have the same dim size so
this is not so good for persp.
I saw in the Dr. S tips page on the s+ web page how to use cloud
to do 3D sphere [i need ellipses though]. But as far as I have been able
to see, cloud axis values are "relative", centred around 0 for each axis
[?]. I would like my range(x) (y) and (z) to be 0,255, so I can plot my
means, then make the spheres around the 3 standard deviations. As far as
I know and have
tried, cloud does not work here. I used cloud by z~x+y.
1] can i use my actual data value ranges in cloud?
2] can i place several spheres in a cloud plot? by a loop?
3] should I use persp instead of cloud?
Could you please point me in the right direction and I could finish up
the function.
sphere <- function(n){
# source(sphere.ssc)
# SPHERE Generate sphere.
# Clay M. Thompson 4-24-91, CBM 8-21-92.
# put to splus by chris duke
if(nargs()==0) n <- 20
# -pi <= theta <= pi is a row vector.
# -pi/2 <= phi <= pi/2 is a column vector.
theta <- seq(-n, n, by=2)/n*pi
phi <- t(seq(-n, n, by=2))/n*pi/2
cosphi <- cos(phi)
cosphi[1] <- 0
cosphi[n+1] <- 0
sintheta <- sin(theta)
sintheta[1] <- 0
sintheta[n+1] <- 0
print(sintheta)
x <- crossprod(cosphi, t(cos(theta)))
y <- crossprod(cosphi, t(sintheta))
z <- crossprod(sin(phi), t(rep(1, times=n+1)))
#cloud(z~x+ y)
list(x,y,z)
}
plote <- function(mr=60, mg=60, mb=60, sr=3, sg=8, sb=10) {
# source("plote.ssc")
# plote(60,60,60,3,8,10)
# function [x,y,z] = plote(mr,mg,mb,sr,sg,sb)
# PLOTE - creates a 3D ellipsoid for the distribution given by the args
# and returns points similar to SPHERE
npts <- 10
dat <- sphere(npts)
ed <- matrix(data=0, ncol=3, nrow=3)
ed[1,1] <- sr
ed[2,2] <- sg
ed[3,3] <- sb
n <- npts + 1
# in know, I don't have to use a function like reshape to do this
reshape <- function(x, i, j){
temp <- matrix(x, nrow=i, ncol=j)
temp
}
sp <- cbind(reshape(dat$x,n*n,1), reshape(dat$y,n*n,1),
reshape(dat$z,n*n,1))
spr <- sp%*%ed
x <- reshape(spr[,1]+mr,n,n)
y <- reshape(spr[,2]+mg,n,n)
z <- reshape(spr[,3]+mb,n,n)
list(x, y, z)
}
send plote() to cloud or persp?
any help would be appreciated. Thanks,
chris duke
--
Chris Duke
Image Analysis and Remote Sensing Lab
111 Dept. of Land Resource Science
Univ. of Guelph, Guelph, Ontario, CND, N1G 2W1
(519)824-4120 x4275, lab x4274 fax (519)824-5730
cduke@lrs.uoguelph.ca http://o2.lrs.uoguelph.ca/cduke
-----------------------------------------------------------------------
This message was distributed by s-news@wubios.wustl.edu. To unsubscribe
send e-mail to s-news-request@wubios.wustl.edu with the BODY of the
message: unsubscribe s-news
|