kPCA_arrows | R Documentation |
'kPCA_arrows()' draws arrows on a (kernel) PCA plot to represent the contribution of the original variables to the two displayed Principal Components (PCs).
kPCA_arrows(plot, contributions, colour = "steelblue", size = 4, ...)
plot |
A kernel PCA plot generated by 'kPCA()'. |
contributions |
The variables contributions, for instance obtained via 'kPCA_imp()'. It is not mandatory to draw all the original variables; a subset of interest can be passed on to this argument. |
colour |
Color of arrows and labels. (Defaults: "steelblue"). |
size |
Size of the labels. (Defaults: 4). |
... |
Additional parameters passed on to geom_segments() and geom_text(). |
It is important to note that the arrows are scaled to match the samples' projection plot. Thus, arrows' directions are correct, but do not expect that their magnitudes match the output of 'kPCA_imp()' or other functions('prcomp', 'princomp...'). (Nevertheless, they should at least be proportional to the real magnitudes.)
The PCA plot with the arrows ('ggplot2' object).
dat <- matrix(rnorm(500),ncol=10,nrow=50)
K <- Linear(dat)
## Computing the kernel PCA. The plot represents PC1 and PC2:
kpca <- kPCA(K,plot=1:2)
## Computing the contributions to all the PCS:
pcs <- kPCA_imp(dat,secure=FALSE)
## We will draw the arrows for PC1 and PC2.
contributions <- t(pcs$loadings[1:2,])
rownames(contributions) <- 1:10
kPCA_arrows(plot=kpca$plot,contributions=contributions)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.