Jacqueline Hall
2008-Oct-23 21:16 UTC
[R] map points from scatterplot3d onto 2d fitted plane
Dear R helpers, I have a 3D scatter plot that I have generated from scatterplot3d (which looks great- thanks!) and I can see that the points in my graph fall in a plane. Following the example 5 from 3D scatter plot (below) I have fitted a regression plane. Now what I would like to do is a rotation so that my new co-ordinate system is about the fitted plane (by finding the normal to the plane using crossprod?) and then map the data points onto this plane. I played with the function xyz.convert from s3d but i think this is mapping to the xy plane whereas i would like to map onto my fitted plane. Is there a package/function that can help me do this that I have missed? or does anyone have any suggestions / sample code to get me started in the right direction? Thanks very much for your help! Jacqueline #R-2.6 ## example 5 data(trees) s3d <- scatterplot3d(trees, type="h", highlight.3d=TRUE, angle=55, scale.y=0.7, pch=16, main="scatterplot3d - 5") # Now adding a regression plane to the "scatterplot3d" attach(trees) my.lm <- lm(Volume ~ Girth + Height) s3d$plane3d(my.lm, lty.box = "solid") [[alternative HTML version deleted]]
Jacqueline Hall <jacqueline.a.hall <at> googlemail.com> writes:> I have a 3D scatter plot that I have generated from scatterplot3d (which > looks great- thanks!) and I can see that the points in my graph fall in a > > Is there a package/function that can help me do this that I have missed? or > does anyone have any suggestions / sample code to get me started in the > right direction?Nothing beats package rgl; there are some example similar to your's coming with the package. Dieter
Jacqueline Hall wrote:> Dear R helpers, > > I have a 3D scatter plot that I have generated from scatterplot3d (which > looks great- thanks!) and I can see that the points in my graph fall in a > plane. > Following the example 5 from 3D scatter plot (below) I have fitted a > regression plane. > Now what I would like to do is a rotation so that my new co-ordinate system > is about the fitted plane (by finding the normal to the plane using > crossprod?) and then map the data points onto this plane. > > I played with the function xyz.convert from s3d but i think this is mapping > to the xy plane whereas i would like to map onto my fitted plane. > > Is there a package/function that can help me do this that I have missed? or > does anyone have any suggestions / sample code to get me started in the > right direction?Typing vignette(package="scatterplot3d") shows the package comes with a package vignette. Further on typing vignette("s3d", package="scatterplot3d") shows the vignette which has been published (as a former more compact version) as Ligges, U. and M?chler, M. (2003). Scatterplot3d - an R Package for Visualizing Multivariate Data. Journal of Statistical Software 8(11), 1-20. See page 22 of the package vignette for an example that could be rewritten for the trees data you used below as follows: s3d <- scatterplot3d(trees, angle=55, scale.y=0.7, pch=16, main="scatterplot3d - 5") my.lm <- lm(Volume ~ Girth + Height, data = trees) s3d$plane3d(my.lm, lty.box = "solid") orig <- s3d$xyz.convert(trees) plane <- s3d$xyz.convert(trees[,1], trees[,2], fitted(my.lm)) i.negpos <- 1 + (resid(my.lm) > 0) segments(orig$x, orig$y, plane$x, plane$y, col = c("blue", "red")[i.negpos], lty = (2:1)[i.negpos]) Best, Uwe Ligges> Thanks very much for your help! > Jacqueline > > #R-2.6 > ## example 5 > data(trees) > s3d <- scatterplot3d(trees, type="h", highlight.3d=TRUE, > angle=55, scale.y=0.7, pch=16, main="scatterplot3d - 5") > # Now adding a regression plane to the "scatterplot3d" > attach(trees) > my.lm <- lm(Volume ~ Girth + Height) > s3d$plane3d(my.lm, lty.box = "solid") > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at 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.