Riley, Steve
2011-May-11 11:12 UTC
[R] Adding reference line or plane to cloud or wireframe
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! Steve Steve Riley, PharmD, PhD Clinical Pharmacology Specialty Care Medicines Development Group Pfizer Inc. 445 Eastern Point Rd MS 8260-2513 Groton, CT 06340 Email: steve.riley@pfizer.com <mailto:steve.riley@pfizer.com> Phone: (860) 441-3435 Fax: (860) 686-5672 [[alternative HTML version deleted]]
Duncan Murdoch
2011-May-11 11:50 UTC
[R] Adding reference line or plane to cloud or wireframe
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