基于ggplot2包以及corrplot包的相關(guān)矩陣可視化包ggcorrplot僻爽,ggcorrplot包提供對(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")