On 11/05/2011 7:12 AM, Riley, Steve wrote:
All,



I am wondering how one might add a reference line or plane to a cloud or
wireframe plot. I have been unable to figure this out. Let's say I would
like to draw a reference for some value of wt in the example below:



cl<- 54.1

age<- 10:80

wt<- 25:160



sim<- expand.grid(age = age,wt = wt)



sim$cl<- cl*(sim$wt/70)**0.412 * (sim$age/50)**0.152



library(lattice)



print(cloud(cl~wt*age, data = sim))





Any thoughts you could provide are greatly appreciated. Thank you!

It is tricky in lattice or classic graphics, because they depend on using the painter's algorithm to handle occlusion of some objects by others. You need to draw the part of the line or plane that is in front of the surface after you draw the surface, but the part behind it needs to be drawn first (or not at all).

If you use rgl, these calculations are done in hardware, and it's somewhat easier. For example, with your data as above,

open3d()
persp3d(age, wt, sim$cl, col="blue")

fit <- lm(cl ~ wt + age, data=sim)
coefs <- coef(fit)

planes3d(coefs["wt"], coefs["age"], -1, coefs["(Intercept)"], alpha=0.5)

(The planes3d function is new. It's still only on the R-forge development version of rgl, not on CRAN yet. Similarly, abclines3d is a new addition for drawing reference lines.)

Duncan Murdoch

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to