如何在正确的视图中创建皮尔逊相关矩阵

How to create the pearson correlation matrix in correct view

我有一个简单的问题。我尝试使用 R(corrplot 包)获得皮尔逊相关性。我获得了正确的矩阵,但我只想在主对角线下方的数字为 1 的部分中获得数字。

我使用这个脚本:

cor(Dati_Rsoftware[,1:17], method=c('pearson'))
###Correlation calculation###

library(corrplot)
Bisznia = cor(Dati_Rsoftware[,1:17], method=c('pearson'))
corrplot(Bisznia)
###Matrix###

感谢您的帮助。 乔

使用玩具数据集iris,加载包:

library(corrplot)

iris_cor <- cor(iris[,1:4], method = c("pearson"))
corrplot(iris_cor, method = "circle", type = "upper")

输出如下:

参数 type="upper" 是仅绘制高于原则对角线的圆的关键。

你看过documentation了吗?根据您提供的图片判断,您正在寻找如下内容:

library(corrplot)
library(dplyr)

as_tibble(mtcars) %>% 
    cor() %>% 
    corrplot(type = "lower",        # can be upper, lower, or full
             method = "color",      # can also be circle, square, etc.
             addCoef.col = "black", # text color
             number.cex = .7        # text size
             )