微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

R相关矩阵使用ggcorr仅显示部分数据

如何解决R相关矩阵使用ggcorr仅显示部分数据

我有一个包含不同数值和阶乘数据的大型数据集。用ggcorr(data)进行相关图可以使我得到一个有趣的图形,但是其中一半对我来说是无用的,因为我只需要在描述性数据和度量数据之间建立相关性即可。根据我的数据,将给出一个5 * 4的正方形,而不是长度为9的三角形。 有没有办法做到这一点?有没有一种方法可以将P值添加为星形?

类似于我的简短数据集:

State <-as.factor(c("land","loc2","loc3"))
Age <- c(20,24,22,49)
Education<- as.factor(c(2,2,3,1))
AreaHill <- c(NA,18,2)
AreaPlain <-c(1,NA,NA)
Style <-as.factor(c("s2","s3","s2","s2"))
descriptive <-cbind(State,Age,Education,AreaHill,AreaPlain,Style)

Measure1 <-c(2,4,2)
Measure2 <-c(4,5)
Measure3 <-c(2,1,1)
Measure4 <-c(2,2)

measures <- cbind(Measure1,Measure2,Measure3,Measure4)
data <- cbind(State,Style,Measure1,Measure4)

library(Ggally)
ggcorr(data)

``` Here is what I have so far
[The correlations Now,as a triangle][1]
and here is what I want to have: correlations between categories,but not among them,as well as the p. value as a star (or anything else).
[The potential image with correlation between some categories but without correlation among them][2]


  [1]: https://i.stack.imgur.com/a5Uib.jpg
  [2]: https://i.stack.imgur.com/cLUSP.jpg

解决方法

使用@Jonni所示的plot.matrix包,可以制作不显示所有组合的相关矩阵

lib_a.so

现在我必须再次添加行名,

library(plot.matrix)
corr.data<-correlate(data) # make all the correlations,as before
square <-corr.data[c(2:7),c(8:11)]# cut out the ones I am interested in
square <- as.matrix(square) # it works only as a matrix
plot(square) ## now it works,when as a matrix
plot(as.cor(square),reorder = F) # plot as correlation

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。