library(rggobi) library(scagnostics) .GGobiCall <- getNamespace("rggobi")$.GGobiCall ggobi_display_set_tour_projection <- function (gd, value) { normal <- all(colSums(value^2) - 1 < 0.001) orthog <- all(crossprod(value, value) - diag(ncol(value)) < 0.001) if (!normal) stop("Matrix is not normal (colSums do not equal 1)") if (!orthog) stop("Matrix is not orthogonal") invisible(.GGobiCall("setTourProjection", gd, pmode(gd), value)) } ggobi_display_get_tour_projection <- function (gd) { mat <- .GGobiCall("getTourProjection", gd, pmode(gd)) mat[, 1:2] } getproj <- function(p, x=NULL) { pp <- rnorm(p) if (length(x) > 0) { pp <- pp - crossprod(x,pp)*x } return(pp/sqrt(crossprod(pp))) } proj <- function(df) { df <- as.matrix(df) cols <- ncol(df) pp1 <- getproj(cols) pp2 <- getproj(cols, pp1) # plot(df %*% pp1, df %*% pp2) return(cbind(pp1,pp2)) } ortho <- function(x) { pp1 <- x[,1]/sqrt(crossprod(x[,1])) pp2 <- x[,2] - crossprod(x[,2],pp1)*pp1 pp2 <- pp2/sqrt(crossprod(pp2)) return(cbind(pp1,pp2)) }