当前位置:网站首页>Example analysis of corrplot related heat map beautification in R language
Example analysis of corrplot related heat map beautification in R language
2022-06-24 19:21:00 【Yisu cloud】
R Language corrplot Example analysis of heat map beautification
This article mainly introduces “R Language corrplot Example analysis of heat map beautification ” Knowledge about , Xiaobian shows you the operation process through practical cases , The operation method is simple and fast , Practical , Hope this article “R Language corrplot Example analysis of heat map beautification ” The article can help you solve problems .
Introduce
R corrplot package Provides a visual exploration tool on the correlation matrix , The tool supports automatic variable reordering , To help detect hidden patterns between variables .
corrplot Very easy to use , And in the visual method 、 Graphic layout 、 Color 、 legend 、 Text labels and other aspects provide a wealth of drawing options . It also provides p Values and confidence intervals , To help users determine the statistical significance of the correlation .
corrplot() There are about 50 Parameters , But the most common parameters are only a few . In most scenes , We can get a correlation matrix with only one line of code .
1. Load package
library(corrplot)
2. Load data
mtcars
3. mapping
corrplot(M, method = 'number')

#order Sorting method original( Default ), Eigenvector angle sorting AOE, The first principal component order FPC, Hierarchical clustering sorting hclust, In alphabetical order alphabetcorrplot(M, method = 'color', order = 'hclust')

# Shape default circle, In addition to that square,ellipse,number,pie,shade,colorcorrplot(M,method="circle")

corrplot(M,method="square")

corrplot(M,method="ellipse")

corrplot(M,method="pie")

#diag = FALSE, Do not show... In the middle 1 Lattice of corrplot(M,method="square",diag = FALSE)

#type Show only the lower part of the correlation , In addition, there are parameters full,uppercorrplot(M, method = 'square', order = 'FPC', type = 'lower', diag = FALSE)

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

# Mix numbers and graphs corrplot.mixed(M, order = 'AOE')

# Mix the upper pie chart , The lower shadow corrplot.mixed(M, lower = 'shade', upper = 'pie', order = 'hclust')

# Hierarchical clustering , Mark out 2 individual clustercorrplot(M, order = 'hclust', addrect = 2)

# Define the circled cluster, And the color and line of the loop line corrplot(M, method = 'square', diag = FALSE, order = 'hclust', addrect = 3, rect.col = 'blue', rect.lwd = 3, tl.pos = 'd')

4. Personalize the clustering method
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. Add a personalized matrix
library(magrittr)# Method 1i = dist2order(Z, 'R2E')corrplot(Z[i, i], cl.pos = 'n') %>% corrRect(c(1, 9, 15))

# Method 2corrplot(Z, order = 'AOE') %>% corrRect(name = c('tail', 'airborne', 'venomous', 'predator'))
# Method 3 Direct designation r = rbind(c('eggs', 'catsize', 'airborne', 'milk'), c('catsize', 'eggs', 'milk', 'airborne'))corrplot(Z, order = 'hclust') %>% corrRect(namesMat = r)
6. color setting
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.* Parameters are often used in color legends :cl.pos Location of color labels ('r'type='upper''full''b'type='lower''n'),cl.ratio Width recommendations for color legend 0.1~0.2#tl.* Parameters are often used in text legends :tl.pos Location for text labels ,tl.cex Text size ,tl.srt Rotation of text 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')
About “R Language corrplot Example analysis of heat map beautification ” That's all for , Thanks for reading . If you want to know more about the industry , You can pay attention to the Yisu cloud industry information channel , Xiaobian will update different knowledge points for you every day .
边栏推荐
猜你喜欢

干货 | 新手经常忽略的嵌入式基础知识点,你都掌握了吗?

Volcano becomes spark default batch scheduler

Interpreting harmonyos application and service ecology

starring开发HttpJson接入点+数据库

Freeswitch uses origin to dialplan

The sharp sword of API management -- eolink

通过SCCM SQL生成计算机上一次登录用户账户报告

Source code analysis of ArrayList

論文解讀(SR-GNN)《Shift-Robust GNNs: Overcoming the Limitations of Localized Graph Training Data》

企业网络管理员必备的故障处理系统
随机推荐
Introduction and download of nine npp\gpp datasets
8 challenges of BSS application cloud native deployment
Why useevent is not good enough
使用阿里云RDS for SQL Server性能洞察优化数据库负载-初识性能洞察
企业网络管理员必备的故障处理系统
Does version 2.2.0 support dynamic addition of MySQL synchronization tables
thinkphp6中怎么使用jwt认证
小滴课堂海量数据处理商用短链平台大课
Introduction to alos satellite
Volcano devient l'ordonnanceur de lots par défaut Spark
敏捷之道 | 敏捷开发真的过时了么?
What type of datetime in the CDC SQL table should be replaced
Will the CDC read out of order when I use SQL
制造业项目MDM主数据项目实施心得
Volcano成Spark默认batch调度器
一文理解OpenStack网络
Freeswitch uses origin to dialplan
Xiaobai, let me ask you guys, is MySQL binlog extracted by CDC in strict order
Volcano becomes spark default batch scheduler
Starring develops httpjson access point + Database