作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在创建一个山脊图来比较几个组(使用 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")
请看下面的 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")
除非您特别有兴趣让 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")
关于r - 向脊线图添加显着性括号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68576284/
我是一名优秀的程序员,十分优秀!