Deepseek也沒有解決,還是好好學(xué)R代碼。
1、讀入數(shù)據(jù)data
2、計(jì)算相關(guān)系數(shù)
cor_result<-corr.test(data,
? ? ? ? ? ? ? ? method = "pearson")?
# 提取需要的相關(guān)系數(shù)和p值矩陣
cor_matrix <- cor_result$r [-12:-21,12:21] # 相關(guān)系數(shù)矩陣
p_value_matrix <- cor_result$p [-12:-21,12:21] # p值矩陣
mm<-range(cor_matrix)? #系數(shù)范圍
3、繪圖,有意義的顯示,無意義的相關(guān)系數(shù)不顯示
corrplot::corrplot(cor_matrix,
? ? ? ? is.corr = F,? #非對(duì)稱矩陣
? ? ? ? method = "color",? ? ? # 使用顏色顯示相關(guān)系數(shù)
? ? ? ? type = "upper",? ? ? ? # 只顯示上三角矩陣
? ? ? ? tl.col = "black",? ? ? # 設(shè)置文本顏色
? ? ? ? tl.srt = 45,? ? ? ? ? ? # 設(shè)置文本旋轉(zhuǎn)角度
? ? ? ? addCoef.col = "black",? # 添加相關(guān)系數(shù)的數(shù)值
? ? ? ? p.mat = p_value_matrix, # 添加p值矩陣
? ? ? ? sig.level = 0.05,? ? ? # 顯著性水平
? ? ? ? insig = "blank",? ? ? ? # 顯示不顯著的區(qū)域?yàn)榭瞻?/p>
? ? ? ? diag = FALSE,? ? ? ? ? # 去掉對(duì)角線
? ? ? ? number.cex = 1.2,? ? ? ? # 設(shè)置相關(guān)系數(shù)值的字體大小
? ? ? ? number.font = 2,
????? col = COL2('PRGn'))?