【发布时间】:2018-07-09 15:39:47
【问题描述】:
我试图在 R 中的相关矩阵中仅绘制相关系数高于 0.6 的关系。目前,我正在使用包“corr_test”来运行 Pearson 相关,然后我使用“ggcorrplot”来制作我的矩阵.如何修改我的代码以仅绘制强于 +.6/-.6 的相关系数?
以下是我当前的代码:
##New Pearson Correlation Script##
#Load in the stuff you dont have
install.packages("psych")
install.packages("ggcorrplot")
#Load it up
library("psych")
library("ggcorrplot")
library("ggplot2")
##Load in your datasets, just fill D1 if one matrix, load D2 as well if 2 matrices
D1 =class
D2 =metab
#Run the correlation
test =corr.test(D1, y = D2, use = "complete")
#r is the correlation matrix
r = test$r
#p is the p-values
p = test$p
#plot it out
testplot= ggcorrplot(r, method = "circle" ,lab_size= 0.3, tl.cex = 8, outline.col = "black", tl.col = "black")+
theme(axis.text.y=element_text(size=9),
axis.text.x = element_text(size=9, angle=90))
print(testplot)
单击Here(Google Drive 文件)查看我一直在使用的相关系数的小数据集。
谢谢!
【问题讨论】:
-
你的意思是相关系数绝对值大于0.6?
-
data(class)给出Warning message: In data(class) : data set ‘class’ not found和data(metab)相同 -
我想给出我的整个代码,但提供的数据表已经有相关系数。我自己运行了相关性并提取了要绘制的系数
-
是的,当然是绝对值
标签: r correlation