3

Suppose I ran a factor analysis & got 5 relevant factors. Now, I want to graphically represent the loading of these factors on the variables. Can anybody please tell me how to do it. I can do using 2 factors. But can't able to do when number of factors are more than 2.

The 2 factor plotting is given in "Modern Applied Statistics with S", Fig 11.13. I want to create similar graph but with more than 2 factors. Please find the snap of the Fig mentioned above: enter image description here

X & y axes are the 2 factors.

Regards, Ari

Beta
  • 1,638
  • 5
  • 33
  • 67
  • I don't have access to a copy of the book you mention. Can you provide us with a picture? – Roman Luštrik Jul 27 '11 at 19:13
  • 1
    Why don't you provide us with a) a way to reproduce some sample data (try `dput`), and b) the code that you have working so far, so that we might have a hope at solving your problem? Please read this http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example Thanks. – Ari B. Friedman Jul 27 '11 at 19:37
  • I didn't put the code or the data as the problem is too general. Suppose somebody ran a factor analysis & find 5 factors that perfectly reflect the underline variables. Now he want to visualize it using a graph (e.g. want to present it to a novice.). I just want to know how to create the graph using 5 factors. – Beta Jul 27 '11 at 19:46
  • I don't understand why somebody put a negative vote to my question!!! The person didn't even bother to clarify it :x( – Beta Jul 27 '11 at 20:24
  • 1
    I didn't down-vote it, but I do think you should add a brief code snippet--particularly since you say "I can do using 2 factors." Reproducibility is very important. The likelihood of your finding someone who knows factor analysis well enough to give you working code off the top of their head is very small. But there are many here who are proficient in R and could very quickly use that knowledge to come up with an answer. Asking them to spend time coming up with sample data and reproducing work you've already done, just to extend it to more factors, however, is a bit of a stretch. – Ari B. Friedman Jul 27 '11 at 20:54
  • Ah! I really didn't think of this situation. From the next time I put any question I'll try to gve the code or samaple data or both. Thanks gsk3 for pointing this out to me. – Beta Jul 28 '11 at 04:03

3 Answers3

4

Beware: not the answer you are looking for and might be incorrect also, this is my subjective thought.

I think you run into the problem of sketching several dimensions on a two dimension screen/paper. I would say there is no sense in plotting more factors' or PCs' loadings, but if you really insist: display the first two (based on eigenvalues) or create only 2 factors. Or you could reduce dimension by other methods also (e.g. MDS).

Displaying 3 factors' loadings in a 3 dimensional graph would be just hardly clear, not to think about more factors.


UPDATE: I had a dream about trying to be more ontopic :)

You could easily show projections of each pairs of factors as @joran pointed out like (I am not dealing with rotation here):

f <- factanal(mtcars, factors=3)
pairs(f$loadings)

enter image description here

This way you could show even more factors and be able to tweak the plot also, e.g.:

f <- factanal(mtcars, factors=5)
pairs(f$loadings, col=1:ncol(mtcars), upper.panel=NULL, main="Factor loadings")
par(xpd=TRUE) 
legend('topright', bty='n', pch='o', col=1:ncol(mtcars), attr(f$loadings, 'dimnames')[[1]], title="Variables")

enter image description here

Of course you could also add rotation vectors also by customizing the lower triangle, or showing it in the upper one and attaching the legend on the right/below etc.

Or just point the variables on a 3D scatterplot if you have no more than 3 factors:

library(scatterplot3d)
f <- factanal(mtcars, factors=3)
scatterplot3d(as.data.frame(unclass(f$loadings)), main="3D factor loadings", color=1:ncol(mtcars), pch=20)

enter image description here

Note: variable names should not be put on the plots as labels, but might go to a distinct legend in my humble opinion, specially with 3D plots.

daroczig
  • 28,004
  • 7
  • 90
  • 124
  • Thanks Darcozig! Actually people don't always understand numbers. But if you show them in graphs, things become lot more easy. That's why plotting factors in graphs. I'm still not sure whether this will really solve my problem or increase my problem :) But let see! – Beta Jul 28 '11 at 04:12
  • @user697363: You are right! I was thinking of the problem last night and later Joran's answer brought me some light: well, it could be done in some way. I updated my answer, I hope you may find some useful pieces. – daroczig Jul 28 '11 at 20:32
  • @darcozig: Thanks for the answer. Glad to hear that I inspired somebody to think. All the answers are interesting. This question became a great learning for me. – Beta Jul 29 '11 at 06:29
3

It looks like there's a package for this: http://factominer.free.fr/advanced-methods/multiple-factor-analysis.html

Comes with sample code, and multiple factors. Load the FactoMineR package and play around.

Good overview here: http://factominer.free.fr/docs/article_FactoMineR.pdf

Graph from their webpage: FactoMineR graph


You can also look at the factor analysis object and see if you can't extract the values and plot them manually using ggplot2 or base graphics.

Ari B. Friedman
  • 71,271
  • 35
  • 175
  • 235
  • Thank gsk3 for referring me the new package!I didn't know about it.And for the answer too. – Beta Jul 28 '11 at 04:09
  • I am not sure: it seems to me that still 2 factors are shown, though the plot seems really nice. – daroczig Jul 28 '11 at 20:31
  • @daroczig I think you're right. Leaving the answer up because the package itself looks to have useful functions for multiple factor analysis. – Ari B. Friedman Jul 28 '11 at 20:40
2

As daroczig mentions, each set of factor loadings gets its own dimension. So plotting in five dimensions is not only difficult, but often inadvisable.

You can, though, use a scatterplot matrix to display each pair of factor loadings. Using the example you cite from Venables & Ripley:

#Reproducing factor analysis from Venables & Ripley
#Note I'm only doing three factors, not five
data(ability.cov)
ability.FA <- factanal(covmat = ability.cov,factor = 3, rotation = "promax")
load <- loadings(ability.FA)
rot <- ability.FA$rot

#Pairs of factor loadings to plot
ind <- combn(1:3,2)
par(mfrow = c(2,2))
nms <- row.names(load)
#Loop over pairs of factors and draw each plot
for (i in 1:3){
    eqscplot(load[,ind[1,i]],load[,ind[2,i]],xlim = c(-1,1),
        ylim = c(-0.5,1.5),type = "n",
        xlab = paste("Factor",as.character(ind[1,i])),
        ylab = paste("Factor",as.character(ind[2,i])))
    text(load[,ind[1,i]],load[,ind[2,i]],labels = nms)

    arrows(c(0,0),c(0,0),rot[ind[,i],ind[,i]][,1],
        rot[ind[,i],ind[,i]][,2],length = 0.1)
}

which for me resulting in the following plot:

enter image description here

Note that I had to play a little with the the x and y limits, as well as the various other fiddly bits. Your data will be different and will require different adjustments. Also, plotting each pair of factor loadings with five factors will make for a rather busy collection of scatterplots.

joran
  • 169,992
  • 32
  • 429
  • 468
  • Thanks Joran! Your answer is really helpful.And you are right, plotting 5 factors mght not make sense. But let me try on my dataset & see the result. – Beta Jul 28 '11 at 04:08