Skip to content
Prev 207254 / 398503 Next

3d trend line

On 22/01/2010 8:52 AM, mlcarte3 wrote:
This will do it:

# Generate some correlated data
x <- matrix(rnorm(3000)+2:4, ncol=3)
y <- x %*% matrix(c(1,-2,3,2,3,4,3,4,4), 3,3)

# Plot it
library(rgl)
plot3d(y)

# Compute the principle components
pc <- princomp(y)

# Plot a line corresponding to the main one
centre <- pc$center
direction <- pc$loadings[,1]
segments3d(rbind(min(pc$scores[,1])*direction + centre,
                 max(pc$scores[,1])*direction + centre))