correlation - 如何从使用 GGally 完成的相关矩阵中删除“Corr”文本?
问题描述
我已将以下代码用于相关矩阵
library(ggplot2)
library(GGally)
ggpairs(CorrelationBINA, title="Correlation matrix of BINA dhan7",
upper = list(continuous= wrap("cor", size = 10)),
lower = list(continuous ="smooth"))
并得到以下相关矩阵。从矩阵的上三角形中,我想删除“Corr”这个词,只保留相关值。
解决方案
这需要一个用户定义的函数,计算相关性,四舍五入到小数点后两位,然后显示此文本而不是具有“Corr”项的相关值默认值:
#This function identifies correlation for each pair of variables that will go into ggpairs command written later
cor_func <- function(data, mapping, method, ...){
x <- eval_data_col(data, mapping$x)
y <- eval_data_col(data, mapping$y)
corr <- cor(x, y, method=method, use='complete.obs')
ggally_text(
label = as.character(round(corr, 2)),
mapping = aes(),
xP = 0.5, yP = 0.5,
color = 'black',
...
)
}
ggpairs(iris[-5],
upper = list(continuous = wrap(cor_func,
method = 'spearman')))
推荐阅读
- objective-c - iOS13:如何检测状态栏点击事件?
- ruby - Ruby:如何解码部分编码或完全编码的字符串?
- python - ArgumentParser:从帮助消息中删除参数的大写名称
- c# - 如何拥有具有单独属性的列表,而不是将整个列表置于单个属性下
- sql-server - 我需要在 sql server 中将日期 (25/01/2019) 转换为 Jan'19 格式
- compilation - 安装gtest的问题,由于巨大的错误无法编译
- visual-studio-2017 - SingleFileGenerator / Run Custom Tool 不适用于新的 vs2017 项目类型
- javascript - 数组排序封装排序不起作用
- html - 操作表时数据未绑定到模型
- c# - 如何使 ViewModel 从 View 中使用的组件调用方法 - WPF Prism