[R] Adding reference line or plane to cloud or wireframe
Duncan Murdoch
murdoch.duncan at gmail.com
Wed May 11 13:50:51 CEST 2011
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
More information about the R-help
mailing list