将相关测试结果添加到ggplot

时间:2018-02-16 16:24:03

标签: r ggplot2 annotations

我尝试创建getDisplayName()并添加我已完成的相关性测试的结果。 有点像:

ggplot

无论我尝试什么,我都会收到错误消息。 有什么想法吗?

2 个答案:

答案 0 :(得分:2)

开发中有一个包可以为您执行此操作(ggstatsplot在CRAN上)。

以下是如何创建相关图的示例:

    ggstatsplot::ggscatterstats(data = iris, x = Sepal.Length, y = Sepal.Width,
test = 'pearson', marginal = TRUE, marginaltype = 'histogram')

这将生成如下图(您可以类似地从Spearman的rho(test = 'spearman')或强大的相关性测试(test = 'robust')获得结果):

enter image description here

查看该功能的文档以获取更多信息。

答案 1 :(得分:0)

我实际上已经通过使用stat_cor()软件包中的ggpubr向该地块添加了统计详细信息

library(ggpubr)
p+stat_cor(method="pearson")