这是我正在处理的数据集示例,我在其中运行变量step
和之间的 pearson 相关性测试z
:
> head(datacorr)
Date & Time [Local] Latitude Longitude step x y z
1 2018-06-18 15:32:00 -2.436589 34.81398 4410.099 14 10 18.24621
2 2018-06-18 15:36:00 -2.438691 34.81222 4620.307 11 15 18.60108
3 2018-06-18 15:40:00 -2.438472 34.81164 4682.904 112 164 198.84468
4 2018-06-18 15:44:00 -2.437794 34.81141 4702.586 90 278 293.42787
5 2018-06-18 15:48:00 -2.437766 34.81177 4662.585 11 7 13.05272
6 2018-06-18 15:52:00 -2.437416 34.81284 4541.207 16 2 16.17849
我在运行测试和创建基本测试方面没有问题,plot()
但我想使用ggscatter()
from package进行更详细的可视化ggpubr
。这是我的脚本及其输出:
> corre<-cor.test(datacorr$step, datacorr$z, method=c("pearson"))
> print(corre)
Pearson's product-moment correlation
data: datacorr$step and datacorr$z
t = -6.2382, df = 15021, p-value = 4.546e-10
alternative hypothesis: true correlation is not equal to 0
95 percent confidence interval:
-0.06676964 -0.03487023
sample estimates:
cor
-0.0508329
> plot(datacorr$step,datacorr$z)
> step<-datacorr$step
> activityz<-datacorr$z
> library("ggpubr")
> ggscatter(datacorr, x = step, y = activityz,
+ add = "reg.line", conf.int = TRUE,
+ cor.coef = TRUE, cor.method = "pearson",
+ xlab = "Step Length", ylab = "Activity Z")
Error in .check_data(data, x, y, combine = combine | merge != "none") :
Can't find the y elements in the data.
我使用了ggscatter()
基于另一篇文章的代码。有谁知道为什么我一直有错误?我是 R 新手,但在我看来,我正确定义了所有参数。如果您对如何在 R 中可视化皮尔逊相关检验(特征线、r 系数、p 值等)有任何选择,我愿意接受建议。
任何帮助表示赞赏!