網(wǎng)站首頁 編程語言 正文
準(zhǔn)備數(shù)據(jù)
兩組變量的數(shù)據(jù)可以像下面這樣處理,分別保存在兩個(gè)csv文件中。
> # 導(dǎo)入數(shù)據(jù)及數(shù)據(jù)預(yù)處理 > setwd("D:/weixin/") > rows <- read.csv("rows.csv") > cols <- read.csv("cols.csv") > str(rows) 'data.frame': 100 obs. of 6 variables: $ r1: num 476 482 640 452 308 ... $ r2: num 2059 1987 1952 1927 1854 ... $ r3: num 513 601 682 497 463 ... $ r4: num 2235 2114 2038 1945 1916 ... $ r5: num 433 376 525 395 238 ... $ r6: num 2028 1943 1802 1775 1748 ... > str(cols) 'data.frame': 100 obs. of 5 variables: $ c1: num 2387 2437 2484 2349 2198 ... $ c2: num 540 535 706 509 359 ... $ c3: num 472 610 465 473 471 ... $ c4: num 74.4 57.3 49.5 51.8 47.6 ... $ c5: num 995 915 1038 794 652 ...
簡(jiǎn)單熱圖
> # 構(gòu)建相關(guān)關(guān)系矩陣 > library(psych) > data.corr <- corr.test(rows, cols, method="pearson", adjust="fdr") > data.r <- data.corr$r # 相關(guān)系數(shù) > data.p <- data.corr$p # p值 > > # 畫熱圖 > library(pheatmap) > pheatmap(data.r, clustering_method="average")
只對(duì)列進(jìn)行聚類
> pheatmap(data.r, clustering_method="average", cluster_rows=F)
將相關(guān)系數(shù)顯示在圖上
> data.r.fmt <- matrix(sprintf("%.2f", data.r), nrow=nrow(data.p)) # 只保留小數(shù)點(diǎn)后兩位 > pheatmap(data.r, clustering_method="average", cluster_rows=F, display_numbers=data.r.fmt)
在圖上加上顯著性標(biāo)記
> getSig <- function(dc) { + sc <- '' + if (dc < 0.01) sc <- '***' + else if (dc < 0.05) sc <- '**' + else if (dc < 0.1) sc <- '*' + sc + } > sig.mat <- matrix(sapply(data.p, getSig), nrow=nrow(data.p)) > str(sig.mat) chr [1:6, 1:5] "*" "***" "" "***" "***" "***" "***" "" "***" "**" ... > pheatmap(data.r, clustering_method="average", cluster_rows=F, display_numbers=sig.mat)
如果想進(jìn)一步改變圖形效果,可以參考pheatmap函數(shù)的用法,修改相應(yīng)的參數(shù)。比如:聚類方式改為complete,加上標(biāo)題等。
> pheatmap(data.r, clustering_method="complete", cluster_rows=F, display_numbers=sig.mat, main="Corr Heatmap")
原文鏈接:https://blog.csdn.net/biocity/article/details/97423272
相關(guān)推薦
- 2022-01-09 出現(xiàn)Got permission denied while trying to connect to
- 2022-04-03 Pandas搭配lambda組合使用詳解_python
- 2022-10-31 C++學(xué)習(xí)之cstdbool和cstddef頭文件封裝源碼分析_C 語言
- 2022-04-20 C++的數(shù)據(jù)類型你真的了解嗎_C 語言
- 2022-10-19 Android?webview加載H5方法詳細(xì)介紹_Android
- 2022-05-04 python機(jī)器學(xué)習(xí)實(shí)現(xiàn)oneR算法(以鳶尾data為例)_python
- 2022-05-12 Kotlin filter 根據(jù)條件過濾數(shù)組
- 2022-04-02 .Net使用SuperSocket框架實(shí)現(xiàn)WebSocket前端_實(shí)用技巧
- 最近更新
-
- window11 系統(tǒng)安裝 yarn
- 超詳細(xì)win安裝深度學(xué)習(xí)環(huán)境2025年最新版(
- Linux 中運(yùn)行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲(chǔ)小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎(chǔ)操作-- 運(yùn)算符,流程控制 Flo
- 1. Int 和Integer 的區(qū)別,Jav
- spring @retryable不生效的一種
- Spring Security之認(rèn)證信息的處理
- Spring Security之認(rèn)證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權(quán)
- redisson分布式鎖中waittime的設(shè)
- maven:解決release錯(cuò)誤:Artif
- restTemplate使用總結(jié)
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實(shí)現(xiàn)加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務(wù)發(fā)現(xiàn)-Nac
- Spring Security之基于HttpR
- Redis 底層數(shù)據(jù)結(jié)構(gòu)-簡(jiǎn)單動(dòng)態(tài)字符串(SD
- arthas操作spring被代理目標(biāo)對(duì)象命令
- Spring中的單例模式應(yīng)用詳解
- 聊聊消息隊(duì)列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠(yuǎn)程分支