gpt4 book ai didi

r - 向脊线图添加显着性括号

转载 作者:行者123 更新时间:2023-12-04 14:53:45 25 4
gpt4 key购买 nike

我正在创建一个山脊图来比较几个组(使用 ggridges 包),并想添加显着性括号以显示某些组水平之间的比较(使用 ggsignif 包)。

但这似乎不起作用,因为在 stat_ggsignif 中计算失败。

这是一个可重现的例子:

set.seed(123)
library(ggsignif)
library(ggridges)
library(ggplot2)

ggplot(iris, aes(x = Sepal.Length, y = Species)) +
geom_density_ridges(scale = 1) +
coord_flip() +
geom_signif(comparisons = list(c("setosa", "versicolor")))
#> Picking joint bandwidth of 0.181
#> Warning in f(..., self = self): NAs introduced by coercion
#> Warning: Computation failed in `stat_signif()`:
#> missing value where TRUE/FALSE needed

reprex package 创建于 2021-07-29 (v2.0.0)

我怎样才能让这两个包一起工作?谢谢。

最佳答案

我没能将 A) geom_density_ridges 和 B) geom_signif 结合起来。原因是(A)要求数值变量为x,类别为y,而(B)要求数值变量为y,类别为x。而且我还没有设法覆盖这种行为。但我假设您选择了 ridge_plots 而不是简单的箱线图,因为您对更丰富的分布可视化感兴趣。为此,有一个比 ridge_plots 更好的解决方案,即所谓的 fiddle 图。请参阅下面的标准箱线图(已标记显着性):

ggplot(iris, aes(x = Species, y = Sepal.Length, fill = Species)) + 
geom_boxplot() +
geom_signif(comparisons = list(c("setosa", "versicolor")), test = "t.test")

enter image description here

请看下面的 fiddle 图(带有抖动和标记的显着性):

ggplot(iris, aes(x = Species, y = Sepal.Length, fill = Species)) + 
geom_violin(trim = F) + geom_jitter() +
geom_signif(comparisons = list(c("setosa", "versicolor")), test = "t.test")

enter image description here

除非您特别有兴趣让 ggridges 和 ggsignif 一起工作,否则这会起作用。请注意, fiddle 图只是一个折叠密度图(有关详细信息,请参阅 https://en.wikipedia.org/wiki/Violin_plot#:~:text=A%20violin%20plot%20is%20a,by%20a%20kernel%20density%20estimator)。

同理,另见sina图(tjebo建议):

library(ggforce)
ggplot(iris, aes(x = Species, y = Sepal.Length, colour = Species)) +
geom_sina() +
geom_signif(comparisons = list(c("setosa", "versicolor")), test = "t.test")

enter image description here

关于r - 向脊线图添加显着性括号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68576284/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com