I'm trying to add "cumulative proportional variance explained" (from PCA) under corrplot's x axis. I referenced corrplot
manual but didn't find out any instruction for doing that. Below is the code I have at the moment using example data.
library("FactoMineR")
library("factoextra")
library("corrplot")
data(decathlon2)
decathlon2.active <- decathlon2[1:23, 1:10]
res.pca <- PCA(decathlon2.active, graph = FALSE)
var <- get_pca_var(res.pca)
corrplot(var$cos2, is.corr=FALSE)
##getting cumulative variance explained from res.pca
variance <- res.pca$eig*100/sum(res.pca$eig)
cumvar <- cumsum(variance)
The problem is how to insert the cumvar
information into the corrplot
's x-axis, such that they match with the corresponding dim*
on top of thecorrplot
, which obviates the need to do a scree plot.
Does anyone know how to do that? Any help will be appreciated.
If you want to display these numbers at the bottom of x-axis:
Repeating your calculations
library("FactoMineR")
library("factoextra")
library("corrplot")
data(decathlon2)
decathlon2.active <- decathlon2[1:23, 1:10]
res.pca <- PCA(decathlon2.active, graph = FALSE)
var <- get_pca_var(res.pca)
variance <- res.pca$eig*100/sum(res.pca$eig)
cumvar <- cumsum(variance)
Making a plot with extra space at the bottom
corrplot(var$cos2, is.corr=FALSE, mar=c(4,0,0,0))
Adding proportion of variance explained under the cells:
text(1:5, 0, round(cumvar[1:5], 2), xpd=TRUE)
And the result: