Skip to content
Prev 293792 / 398503 Next

How to plot PCA output?

Christian, is that 36 samples x 11K variables?  Sounds like it.  Is this spectroscopic data?

In any case, the scores are in the list element $x as follows:

answer <- prcomp(your matrix)

answer$x contains the scores, so if you want to plot the 1st 2 pcs, you could do

plot(answer$x[,1], answer$x[,2])

Because the columns of answer$x contain the scores of the PCs in order.

[I see Jessica just answered...]

If you want the loading plot, it's going to be interesting with all those variables, but this will do it:

plot(1:11000, answer$rotation[,1], type = "l") # for the loadings of the 1st PC

Depending upon what kind of data this is, the 1:11000 could be replaced by something more sensible.  If it is spectroscopic data, then replace it with your frequency values.

By the way, plot(answer) will give you the scree plot to determine how many PCs are worthy.

Good luck. Bryan

***********
Bryan Hanson
Professor of Chemistry & Biochemistry
DePauw University
On May 7, 2012, at 6:22 AM, Christian Cole wrote: