# Variable ordering using PCA

I've downloaded a script to draw a correlation matrix using colored circles. This script allows to order variables using PCA, but I'm not sure how it works. The code responsible for ordering is below:

if (order) {
if(!n==m){
stop("The matrix must be squre if order is TRUE!")
}
x.eigen <- eigen(corr)\$vectors[, 1:2]
e1 <- x.eigen[, 1]
e2 <- x.eigen[, 2]
alpha <- ifelse(e1 > 0, atan(e2/e1), atan(e2/e1) + pi)
corr <- corr[order(alpha), order(alpha)]
}


Question:
What is the interpretation of such ordering and what theory lies behind it?

-
I think that You can write this as an answer. There is everything what I was looking for and I will be glad to accept such answer. –  Tomek Tarczynski Apr 23 '12 at 19:03
It is described in Michael Friendly's American Statistician paper on corrgrams, Preprint PDF here. See section on correlation ordering. Also of potential interest, a presentation by Leland Wilkinson on other potential ways to order heatmaps. Also if you look at the source of the corrgram library you will see some other potential ways to order the data as well.
To describe what the code is doing in a nut-shell, the variables in the correlation matrix are ordered according to the correlation with the first principle component extracted from that same correlation matrix. If you look at the Eigenvector plot in the Friendly paper, the code atan(e2/e1) is the angle of the eigen-vector associated with a particular variable against the first principle component (the horizontal axis). Apparently this approximates the correlation (although to be honest I have not walked myself through the necessary math to convince myself of such an approximation!)