r - 如何绘制双精度型的 Spearman 相关性
问题描述
我正在尝试绘制两个高度相关的变量之间的 Spearman 相关性,但我得到了一个“双重”类型的错误。
错误 - 尝试在两个变量之间使用 spearman 相关性时,不能强制“pairlist”对象键入“double”
我已经对数据进行了子集化,将两列转换为数字数据,并尝试将数据框转换为矩阵,但我仍然遇到同样的错误。
library(ggpubr)
var_sub_set <- as.data.frame(bc_data[ ,c("compactness_mean", "points_mean" )])
Var <- as.data.frame(sapply(var_sub_set, as.numeric))
ggscatter(Var, x = "compactness_mean", y = "points_mean",
add = "reg.line", conf.int = TRUE,
cor.coef = TRUE, cor.method = "spearman",
xlab = "Compactness Mean", ylab = "Points Mean")
数据应绘制在散点图上并显示 p_value 和任何线性线。
dput sample output
structure(list(compactness_mean = c(0.06981, 0.1147, 0.07804,
0.1136, 0.06934, 0.07722, 0.1021, 0.1768, 0.08578, 0.09097, 0.1644,
0.06679, 0.1089, 0.03789, 0.09871, 0.133, 0.09462, 0.07664, 0.1838,
0.01781, 0.04304, 0.02749, 0.01867, 0.01471, 0.08543, 0.0444,
0.02068, 0.1562, 0.02069, 0.063, 0.02583, 0.0226, 0.05598, 0.01692,
0.01737, 0.034, 0.0287, 0.02037, 0.03263, 0.06495, 0.1255)), .Names = c("compactness_mean",
"points_mean"), row.names = c(NA, -569L), class = "data.frame")
解决方案
代码是正确的。重新安装 ggplot2 和 ggpubr 解决了这个问题。
推荐阅读
- python - 如何修复“列表索引必须是整数或切片,而不是列表”错误?
- ios - 可以单独设置我的 AVFoundation 相机吗?
- json - Golang用随机键解组json
- python-3.x - 如何修复“NameError: name 'load_model' is not defined”
- ios - 尝试更改根视图控制器时,App Delegate 崩溃并出现 NSException
- unit-testing - 编写 Substrate 运行时测试时的快进时间
- c# - 如何将 QnA Maker 服务添加到具有 LUIS 的聊天机器人
- gpo - 无法在自定义 2012 gpo 基线中添加 windows 2016 gpo 设置
- java - 使用 AOP 初始化对象
- html - HTML 热键输入控件