-1

I am running PCA using FactoMineR and cannot seem to get the individual points labeled on the Individuals factor map. My dataset ("ExData.csv") contains values in a matrix with 13 rows (labeled A through M) and 10 columns (labeled N through W). I am running the following:

mydata <- read.csv("ExData.csv",header=TRUE,row.names=1)
attach(mydata)

library(FactoMineR)
X <- cbind(N,O,P,Q,R,S,T,U,V,W)
res.pca <- PCA(X)

When PCA runs, I get the Individuals factor map (PCA) with the points labeled 1-13, instead of A trough M. The Variables factor map (PCA) properly labels the loadings N through W.

How can I get the individual points on the Individuals factor map (PCA) plot to be properly labeled (i.e., A through J)?

enter image description here

enter image description here

zx8754
  • 52,746
  • 12
  • 114
  • 209
  • This question does not seem to have any statistical content, it is solely about how to achieve something with a specific programming language. As such, I vote to move it to StackOverflow. –  Oct 05 '15 at 14:17
  • I'm voting to close this question as off-topic because it is about how to use R without a reproducible example. – gung - Reinstate Monica Oct 05 '15 at 16:17
  • Please read the info about [how to ask a good question](http://stackoverflow.com/help/how-to-ask) and how to give a [reproducible example](http://stackoverflow.com/questions/5963269). This will make it much easier for others to help you. – zx8754 Apr 14 '16 at 08:25

1 Answers1

1

The problem is that your matrix X has column names but no row names. So the column labels appear in your PCA plot, but instead of row names you just get row indices as identification of the observations in the plot.

Here's an example:

#install.packages("FactoMineR")
library(FactoMineR)
set.seed(1)

df <- data.frame(matrix(runif(13 * 10),
                        nrow = 13,
                        ncol = 10,
                        dimnames = list(LETTERS[1:13], LETTERS[14:23])))

attach(df)
X <- cbind(N, O, P, Q, R, S, T, U, V, W)

At this point rownames(X) is NULL and PCA(X) can only use the row indices to identify the observation in its plots.

To fix this, simply add the row names to the matrix X that is passed to PCA():

# restore row names
rownames(X) <- rownames(df)   # or something similar in your actual program
res.pca <- PCA(X)

The result looks like this:

enter image description here enter image description here

WhiteViking
  • 3,146
  • 1
  • 19
  • 22