R語(yǔ)言可視化學(xué)習(xí)筆記之相關(guān)矩陣可視化包ggcorrplot


基于ggplot2包以及corrplot包的相關(guān)矩陣可視化包ggcorrplotggcorrplot包提供對(duì)相關(guān)矩陣重排序以及在相關(guān)圖中展示顯著性水平的方法,同時(shí)也能計(jì)算相關(guān)性p-value
<a id="more"></a>

計(jì)算相關(guān)矩陣(cor()計(jì)算結(jié)果不提供p-value)

library(ggcorrplot)
data("mtcars")
corr <- round(cor(mtcars), 1)
head(corr[, 1:6])

用ggcorrplot包提供的函數(shù)cor_pmat()

p.mat <- cor_pmat(mtcars)

head(p.mat[, 1:4])

可視化相關(guān)性矩陣

ggcorrplot(corr)#method默認(rèn)為square

方法為circle

ggcorrplot(corr, method = "circle")

重排矩陣,使用分等級(jí)聚類(lèi)

ggcorrplot(corr, hc.order = TRUE, outline.color = "white")

控制矩陣形狀

ggcorrplot(corr, hc.order = TRUE, type = "lower", outline.color = "white")#下三角形

上三角形

ggcorrplot(corr, hc.order = TRUE, type = "upper", outline.color = "white")

更改顏色以及主題

ggcorrplot(corr, hc.order = TRUE, type = "lower", outline.color = "white", 

ggtheme = ggplot2::theme_gray, colors = c("#6D9EC1", "white", "#E46726"))

添加相關(guān)系數(shù)

ggcorrplot(corr, hc.order = TRUE, type = "lower", lab = TRUE)

增加顯著性水平,不顯著的話(huà)就不添加了

ggcorrplot(corr, hc.order = TRUE, type = "lower", p.mat = p.mat)

將不顯著的色塊設(shè)置成空白

ggcorrplot(corr, p.mat = p.mat, hc.order=TRUE, type = "lower", insig = "blank")

轉(zhuǎn)載https://ytlogos.github.io/2017/06/25/R%E8%AF%AD%E8%A8%80%E5%8F%AF%E8%A7%86%E5%8C%96%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0%E4%B9%8B%E7%9B%B8%E5%85%B3%E7%9F%A9%E9%98%B5%E5%8F%AF%E8%A7%86%E5%8C%96%E5%8C%85ggcorrplot/

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容