当前位置:网站首页>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成Spark默认batch调度器

LabView之MQTT协议使用

How to use R package ggtreeextra to draw evolution tree

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

建立自己的网站(8)

Huawei machine learning service speech recognition function enables applications to paint "sound" and color

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

Source code analysis of ArrayList

Experience of MDM master data project implementation for manufacturing projects

Introduction, download and use of global meteorological data CRU ts from 1901 to 2020
随机推荐
初步学习Nuxt3
Understanding openstack network
一文理解OpenStack网络
为什么 useEvent 不够好
Volcano becomes spark default batch scheduler
The group offsets of the Kafka of the Flink SQL. If the specified groupid is not mentioned
API管理之利剑 -- Eolink
Volcano becomes spark default batch scheduler
Air pollution gas satellite data download tutorial
NOKOV动作捕捉系统使多场协同无人机自主建造成为可能
技术实现 | Apache Doris 冷热数据存储(一)
Introduction to alos satellite
Huawei machine learning service speech recognition function enables applications to paint "sound" and color
Application scenarios of channel of go question bank · 11
Why are life science enterprises on the cloud in succession?
Spatial simulation model acquisition future land cover tutorial
ArrayList源码解析
MySQL binlog data source configuration document, please share
Xiaodi class massive data processing business short chain platform
「碎语杂记」这事儿不安全