简体   繁体   English

在corrplot的x轴下添加其他信息

[英]Adding additional information under corrplot's x axis

I'm trying to add "cumulative proportional variance explained" (from PCA) under corrplot's x axis. 我试图在corrplot的x轴下添加“解释的累积比例方差”(来自PCA)。 I referenced corrplot manual but didn't find out any instruction for doing that. 我参考了corrplot手册,但没有找到执行此操作的任何说明。 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 the corrplot , which obviates the need to do a scree plot. 问题是如何将cumvar信息插入corrplot的x轴,以使其与corrplot顶部的相应dim*匹配,从而避免了进行scree图的需要。

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: 如果要在x轴的底部显示这些数字:

  1. 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) 
  2. Making a plot with extra space at the bottom 进行底部有额外空间的绘图

     corrplot(var$cos2, is.corr=FALSE, mar=c(4,0,0,0)) 
  3. Adding proportion of variance explained under the cells: 在单元格下说明的方差相加比例:

     text(1:5, 0, round(cumvar[1:5], 2), xpd=TRUE) 

And the result: 结果:

结果

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM