AliCivil
AliCivil

Reputation: 2053

Eliminating arrows from a factor analysis Biplot {psych} in R

In the biplot produced by the following code I am trying to get rid of the red lines. I would appreciate it if anyone could help.

library(psych)
data(bfi)
fa2 <- fa(bfi[16:25],2)  #factor analysis
fa2$scores <- fa2$scores[1:100,]  #just take the first 100
biplot(fa2,pch=c(24,21)[bfi[1:100,"gender"]],bg=c("blue","red")[bfi[1:100,"gender"]],
main="Biplot of Conscientiousness and Neuroticism by gender")

enter image description here

Upvotes: 1

Views: 1815

Answers (2)

William Revelle
William Revelle

Reputation: 1230

Months after you posted your question, here is a quick answer. What you are actually asking for is not a biplot (which includes the factor scores as well as the factor loadings), but just a plot of the factor scores. Using your example, just

plot(fa2$scores,bg=c("blue","red")[bfi[1:100,"gender"]],pch=c(24,21)[bfi[1:100,"gender"]],ylim=c(-3,3),xlim=c(-3,3)).

Upvotes: 0

MrFlick
MrFlick

Reputation: 206446

For whatever reason, the psych library decided to re-write it's own biplot so it ignores many of the standard parameters. You can create your own version and just remove the arrow drawing. This method is somewhat hacky but tested with psych_1.4.5. Just verify that

body(biplot.psych)[[c(11,3,12)]]

returns

arrows(0, 0, x$loadings[, 1L] * 0.8, x$loadings[, 2L] * 0.8, 
    col = col[2L], length = arrow.len)

to make sure we are changing the correct line. Then you can do

biplot.psych2<-biplot.psych
body(biplot.psych2)[[11]][[3]][[12]]<-NULL

And then call our new function with

biplot.psych2(fa2,pch=c(24,21)[bfi[1:100,"gender"]],
    bg=c("blue","red")[bfi[1:100,"gender"]],
    main="Biplot of Conscientiousness and Neuroticism by gender")

to get

enter image description here

Upvotes: 1

Related Questions