1

i'm trying to create PCA biplot using FactoMineR. my script look like that:

library(grid)
PCbiplot2 <- function(res.pca, x="Dim.1", y="Dim.2") {
  if(!require(ggplot2)) install.packages("ggplot2")
  # res.pca being a PCA object
  data <- data.frame(obsnames=row.names(res.pca$ind$coord), res.pca$ind$coord)
  plot <- ggplot(data, aes_string(x=x, y=y)) + geom_text(alpha=.4, size=3,     aes(label=obsnames))
  plot <- plot + geom_hline(aes(0), size=.2) + geom_vline(aes(0), size=.2)
  datapc <- data.frame(varnames=rownames(res.pca$var$coord), res.pca$var$coord)
  mult <- min(
    (max(data[,y]) - min(data[,y])/(max(datapc[,y])-min(datapc[,y]))),
    (max(data[,x]) - min(data[,x])/(max(datapc[,x])-min(datapc[,x])))
  )
  datapc <- transform(datapc,
                      v1 = .7 * mult * (get(x)),
                      v2 = .7 * mult * (get(y))
  )
  plot <- plot + coord_equal() + geom_text(data=datapc, aes(x=v1, y=v2,     label=varnames), size = 2, vjust=1, color="red")
  plot <- plot + geom_segment(data=datapc, aes(x=0, y=0, xend=v1, yend=v2),     arrow=arrow(length=unit(0.2,"cm")), alpha=0.75, color="red")
  plot
}

library(FactoMineR)
pca<-read.csv("d_for_pca.csv")
fit2 <- PCA(pca, quali.sup=1, graph=F)
PCbiplot2(fit2)

but i have 395 variables in my data, and what i get is un readeble plot. how can i show only the 15th most contribute variables arrows?

  • 1
    Rather than posting code that cannot be run for lack for data, why not illustrate the task setup on a dataset that is in an available package, say from one of the help pages? It doesn't take 395 variables to illustrate a coding strategy. – IRTFM Dec 06 '14 at 18:17
  • 1
    You also need to express in specific statistical terms what if means to be the most "contribute variables arrows". You certainly need to look at the various possibilities for the 'select' parameter for `plot.PCA` described on its help page. – IRTFM Dec 06 '14 at 18:32
  • thank's for your comment, i took this script from another question in this site(http://stackoverflow.com/questions/22381560/how-to-create-a-biplot-with-factominer?rq=1). anyway as you mentioned - when i built simple PCA with FactoMineR, i used the function 'select="contrib 15"' which made what i want, but i couldn't find how to use it in the biplot script. – yoav shaani Dec 07 '14 at 19:25
  • Without complete code I cannot understand what you just wrote. Edit your question so it is complete and reproducible. You are not yet responding to both comments in a constructive fashion. I'm tempted to vote to close as unclear but will restrain myself for the moment. – IRTFM Dec 07 '14 at 19:44

0 Answers0