Unable to plot PCA data in R. Are scores defined by a given object/name to plot them specifically?

193 Views Asked by At

I have completed a simple PCA function using code that was passed down thru the institution. It outputs scores, loadings, eigen values, % eigen values, # of principal components, mean of columns, std deviation, and lastly the starting data. In the output file the scores are labeled with [[1]] before displaying the scores. I am attempting to plot these scores but I am unsure on how to take that data from this point. I assumed it was assigned to this [[1]] or something in the code defined these scores. This line of code is presented below:

 "#"perform pca on x
 x.svd <- svd(x);
 x.R <- x.svd$u %*% diag(x.svd$d);
 x.C <- t(x.svd$v);
 x.EV <- x.svd$d * x.svd$d
 x.EVpct <- x.EV/sum(x.EV);
 x.EV <- x.EV[1:sm];
 x.EVpct <- x.EVpct[1:sm];
 x.CumEVpct <- x.EVpct;

x.R is the part of the code enacting the scores but that too will not work with the plot function. Hopefully someone understands what I am struggling to ask. Any help is very appreciated. Thank you for your time.

1

There are 1 best solutions below

1
On BEST ANSWER

The easiest thing to do would be:

pc <- prcomp(x)
plot(pc$x[, 1:2]