基于R语言相关系数矩阵可视化图

该文介绍了如何使用R语言的psych和corrplot库对数据进行相关系数分析,并展示了几种不同的相关系数矩阵可视化方法,包括square、number、shade、ellipse、pie等。还展示了如何添加显著性检验到可视化图中,以及如何自定义样式和设置显著性水平。
摘要由CSDN通过智能技术生成

如何做出相关系数矩阵可视化图

下面直接上R语言代码:

install.packages("psych")
install.packages("corrplot")#安装包,如果已安装,请略过
library(psych)
library(corrplot)#载入两个包
data(iris)#机器学习常用神奇数据集——鸢尾花数据集
head(iris)#查看下数据集前五行
irisnew<-iris[,-5]#去除第五列种类变量
cormat<-corr.test(irisnew)#相关系数分析及显著性检验
#最简单的相关系数矩阵可视化
corrplot(cormat$r)
corrplot(cormat$r,method="square")
corrplot(cormat$r,method = "number")
corrplot(cormat$r,method = "shade")
corrplot(cormat$r,method="ellipse")
corrplot(cormat$r,method = "pie")
corrplot(cormat$r,method="square",type="lower",title = "Correlation of iris")
#含显著性检验的相关系数矩阵可视化
cormatp<-cormat$p#单独取出p值矩阵
cormatp[upper.tri(cormatp)]=0#设置p值矩阵上三角等于0
corrplot(cormat$r,method="square",type="lower",title = "Correlation of iris",tl.cex=1.5,tl.pos = "lt",number.cex=1,p.mat=cormatp,sig.level=0.05,insig=c("pch"))
corrplot(cormat$r,method="square",type="full",title = "Correlation of iris",tl.cex=1.5,tl.pos = "lt",number.cex=1,p.mat=cormatp,sig.level=0.05,insig=c("pch"))
corrplot.mixed(cormat$r,upper = "square",lower = "number",diag = "u",tl.cex=1.5,tl.pos = "lt",number.cex=1,p.mat=cormatp,sig.level=0.05,insig=c("pch"))
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

倾城一少

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值