当前位置:网站首页>R语言corrplot相关热图美化实例分析
R语言corrplot相关热图美化实例分析
2022-06-24 18:50:00 【亿速云】
R语言corrplot相关热图美化实例分析
这篇文章主要介绍“R语言corrplot相关热图美化实例分析”的相关知识,小编通过实际案例向大家展示操作过程,操作方法简单快捷,实用性强,希望这篇“R语言corrplot相关热图美化实例分析”文章能帮助大家解决问题。
介绍
R corrplot包 提供了一个在相关矩阵上的可视化探索工具,该工具支持自动变量重新排序,以帮助检测变量之间的隐藏模式。
corrplot 非常易于使用,并在可视化方法、图形布局、颜色、图例、文本标签等方面提供了丰富的绘图选项。它还提供 p 值和置信区间,以帮助用户确定相关性的统计显著性。
corrplot()有大约50个参数,但最常见的参数只有几个。在大多数场景中,我们可以得到一个只有一行代码的相关矩阵图。
1.加载包
library(corrplot)
2.加载数据
mtcars
3.绘图
corrplot(M, method = 'number')

#order排序方法original(默认),特征向量角度排序AOE,第一个主成分顺序FPC,分层聚类排序hclust,按照字母排序alphabetcorrplot(M, method = 'color', order = 'hclust')

#形状默认circle,除此之外还有square,ellipse,number,pie,shade,colorcorrplot(M,method="circle")

corrplot(M,method="square")

corrplot(M,method="ellipse")

corrplot(M,method="pie")

#diag = FALSE,不显示中间为1的格子corrplot(M,method="square",diag = FALSE)

#type仅仅显示下部分相关性,除此之外还有参数full,uppercorrplot(M, method = 'square', order = 'FPC', type = 'lower', diag = FALSE)

corrplot(M, method = 'ellipse', order = 'FPC', type = 'upper', diag = FALSE)

#数字和图混合corrplot.mixed(M, order = 'AOE')

#混合上部饼图,下部阴影corrplot.mixed(M, lower = 'shade', upper = 'pie', order = 'hclust')

#分层聚类,标出2个clustercorrplot(M, order = 'hclust', addrect = 2)

#定义圈出的cluster,以及圈出线的颜色和线条corrplot(M, method = 'square', diag = FALSE, order = 'hclust', addrect = 3, rect.col = 'blue', rect.lwd = 3, tl.pos = 'd')

4.个性化设置聚类方法
install.packages("seriation")library(seriation)list_seriation_methods('matrix')list_seriation_methods('dist')data(Zoo)Z = cor(Zoo[, -c(15, 17)])dist2order = function(corr, method, ...) { d_corr = as.dist(1 - corr) s = seriate(d_corr, method = method, ...) i = get_order(s) return(i)}# Fast Optimal Leaf Ordering for Hierarchical Clusteringi = dist2order(Z, 'OLO')corrplot(Z[i, i], cl.pos = 'n')
# Quadratic Assignment Problemi = dist2order(Z, 'QAP_2SUM')corrplot(Z[i, i], cl.pos = 'n')

# Multidimensional Scalingi = dist2order(Z, 'MDS_nonmetric')corrplot(Z[i, i], cl.pos = 'n')

5.个性化添加矩阵
library(magrittr)#方法1i = dist2order(Z, 'R2E')corrplot(Z[i, i], cl.pos = 'n') %>% corrRect(c(1, 9, 15))

#方法2corrplot(Z, order = 'AOE') %>% corrRect(name = c('tail', 'airborne', 'venomous', 'predator'))
#方法3直接指定r = rbind(c('eggs', 'catsize', 'airborne', 'milk'), c('catsize', 'eggs', 'milk', 'airborne'))corrplot(Z, order = 'hclust') %>% corrRect(namesMat = r)
6.颜色设置
COL1(sequential = c("Oranges", "Purples", "Reds", "Blues", "Greens", "Greys", "OrRd", "YlOrRd", "YlOrBr", "YlGn"), n = 200)COL2(diverging = c("RdBu", "BrBG", "PiYG", "PRGn", "PuOr", "RdYlBu"), n = 200)#cl.*参数常用于颜色图例:cl.pos颜色标签的位置('r'type='upper''full''b'type='lower''n'),cl.ratio颜色图例的宽度建议0.1~0.2#tl.*参数常用于文本图例:tl.pos用于文本标签的位置,tl.cex文本大小,tl.srt文本的旋转corrplot(M, order = 'AOE', col = COL2('RdBu', 10))
corrplot(M, order = 'AOE', addCoef.col = 'black', tl.pos = 'd', cl.pos = 'r', col = COL2('PiYG'))
corrplot(M, method = 'square', order = 'AOE', addCoef.col = 'black', tl.pos = 'd', cl.pos = 'r', col = COL2('BrBG'))
corrplot(M, order = 'AOE', cl.pos = 'b', tl.pos = 'd',col = COL2('PRGn'), diag = FALSE)
corrplot(M, type = 'lower', order = 'hclust', tl.col = 'black', cl.ratio = 0.2, tl.srt = 45, col = COL2('PuOr', 10))
corrplot(M, order = 'AOE', cl.pos = 'n', tl.pos = 'n', col = c('white', 'black'), bg = 'gold2')
关于“R语言corrplot相关热图美化实例分析”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识,可以关注亿速云行业资讯频道,小编每天都会为大家更新不同的知识点。
边栏推荐
- Using alicloud RDS for SQL Server Performance insight to optimize database load - first understanding of performance insight
- NFT pledge liquidity mining system development technology
- Volcano成Spark默认batch调度器
- 多云模式并非“万能钥匙”
- 我用sql形式的会出现cdc读取乱序吗
- subject may not be empty [subject-empty]
- Fabric ledger data block structure analysis (I): how to analyze the smart contract transaction data in the ledger
- Xiaobai, let me ask you guys, is MySQL binlog extracted by CDC in strict order
- Freeswitch使用originate转dialplan
- C self learning function
猜你喜欢

西北工业大学遭黑客攻击?双因素认证改变局面!

Starring V6 platform development take out point process

Do you have all the basic embedded knowledge points that novices often ignore?

Module V

High dimension low code: component rendering sub component

「碎语杂记」这事儿不安全

Value passing and reference passing of value types and reference types in CSharp
![subject may not be empty [subject-empty]](/img/6b/9b57a7ed3ab086036cb6dfe0b31de4.png)
subject may not be empty [subject-empty]

Multi cloud mode is not a "master key"

Introduction and tutorial of SAS planet software
随机推荐
The script implements the automated deployment of raid0
Introduction, download and use of global meteorological data CRU ts from 1901 to 2020
Source code analysis of ArrayList
Why are life science enterprises on the cloud in succession?
小白请教下各位大佬,cdc抽取mysql binlog是严格顺序的吗
ArrayList源码解析
The verifiable certificate of geoscience remote sensing industry
Understanding openstack network
通过SCCM SQL生成计算机上一次登录用户账户报告
使用阿里云RDS for SQL Server性能洞察优化数据库负载-初识性能洞察
R language 4.1.0 software installation package and installation tutorial
一文理解OpenStack网络
Make track map
Microservice system design -- data model and system architecture design
论文解读(SR-GNN)《Shift-Robust GNNs: Overcoming the Limitations of Localized Graph Training Data》
Ask a question. Adbhi supports the retention of 100 databases with the latest IDs. Is this an operation like this
Application scenarios of channel of go question bank · 11
西北工业大学遭黑客攻击?双因素认证改变局面!
应用程序DDoS攻击原理及防御方法
程序员如何做自媒体?