Visualizing Mahalanobis distance in more than 3 dimensions I have 4 dimensional data in a matrix, group1, that looks like the following:
    cost quality safety time
[1,]   13       6      3    4
[2,]   10       4      5   10
[3,]    8       9      3    9
[4,]    7       8      9    9
[5,]    4       4      4    2

I have another matrix, group2, that has a single row and four columns representing the same four variables:
  cost quality safety time
[1,]    2       2      7   11

To identify the distance between group1 and group2 I have calculated the Mahalanobis distance using the mahalanobis function:
mat1 <- matrix(group1, ncol=ncol(group1), dimnames=NULL)
mat2 <- matrix(group2, ncol=ncol(group2), dimnames=NULL)
mahalanobis(mat2, colMeans(mat1), cov(mat1))

The function calculates the distance from group1 to group2 as 13.74883.


*

*How Can I show 4 dimensions of group 1 and group 2 in a graph?

*How can I draw the distance of group2 from group1 using Mahalanobis distance?
I also looked at drawMahal function from the chemometrics package ,but this function doesn't support more than 2 dimensions.
The graph is something like the following:

 A: Take a look at the ggobi web site, and the R code for model-based clustering shows how to compute points on an ellipse, corresponding to the variance-covariance matrix of the data. This is basically the ellipse in your diagram above.
This R code should also work:
f.var.ellipse <- function(x,n=100) {
xm <- apply(x,2,mean)
p <- dim(x)[2]
xn <- dim(x)[1]
xv <- var(x) 
ev <- eigen(xv)
sph <- matrix(rnorm(n*p),ncol=p)
cntr <- t(apply(sph,1,f.norm.vec))
cntr <- cntr%*%diag(sqrt(ev$values))%*%t(ev$vectors)
cntr <- cntr+matrix(rep(xm,n),nrow=n,byrow=T)
return(cntr)
}

You will want to set up a data set, or data frame in R, with the 4 columns of your data, append the points generated by the above function, and add an indicator column which specifies that the row of numbers is "data" or "ellipse". 
You can use the tourr package in R to view it dynamically, or you could use the ggplot2 package to plot it pairwise. 
Take a look at the video LDA video showing high-d variance-covariance ellipses and confidence intervals which shows the ideas for 3D Mahalanobis distance, between hypothesized mean and sample mean. These were done with ggobi, but installing ggobi can be difficult. The tourr package in R gets you pretty close to the ggobi tools.
