Learn R Programming

kerntools (version 1.2.0)

kPCA_arrows: Plot the original variables' contribution to a PCA plot

Description

`kPCA_arrows()` draws arrows on a (kernel) PCA plot to represent the contribution of the original variables to the two displayed Principal Components (PCs).

Usage

kPCA_arrows(plot, contributions, colour = "steelblue", size = 4, ...)

Value

The PCA plot with the arrows (`ggplot2` object).

Arguments

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().

Details

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.)

Examples

Run this code
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)

Run the code above in your browser using DataLab