您的位置:首页 > 其它

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

2017-03-24 00:00 232 查看
如何在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"))


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  可视化 数据