如何将紧凑型字母显示添加到ggboxlot()? [英] How to add compact letter display to ggboxplot()?

查看:21
本文介绍了如何将紧凑型字母显示添加到ggboxlot()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在我创建的框图中添加紧凑的字母显示,是否有可能将cldList()函数与ggboxplot()组合在一起?

这是我的样本数据

library(FSA)
library(multcompView)
library(rcompanion)
library(ggplot2)
library(ggpubr)
library(tidyr)

df_list <- list(
  `1.3.A` = 
    tibble::tribble(
      ~Person, ~Height, ~Weight,
      "Alex",    175,     75,
      "Gerard",    110,     85,
      "Clyde",    120,     79
    ),
  `2.2.A` = 
    tibble::tribble(
      ~Person, ~Height, ~Weight,
      "Missy",    162,     55,
      "Britany",    111,     56,
      "Sussie",    192,     85
    ), 
  `1.1.B` = 
    tibble::tribble(
      ~Person, ~Height, ~Weight,
      "Luke",    177,     66,
      "Alex",    169,     69,
      "Haley",    145,     54
    )
)


lapply(df_list, function(i) ggboxplot(i, x = "Person", y = c("Height", "Weight"), combine = TRUE))
lapply(df_list, function(k) dunnTest(Weight ~ as.factor(Person), method = "bh", data = k))
lapply(df_list, function(i) cldList(P.adj ~ Comparison, threshold = 0.05))

我正在尝试按Person添加重要字母Person,在我的原始数据中,我有30组要比较,将紧凑的字母显示添加到框图将使数据解释变得更加容易。

我在一个列表中也有多个数据帧,我想知道cldList()是否可以包装在lapply()函数中

我希望有人能帮忙。

推荐答案

我是example you already mentioned in a comment的作者。其中一位评论员已经正确地指出了.group栏的来源。然而,当指出您的代码与示例中的代码之间的一般差异时,我发现

  1. 数据

    1a.您的数据每个因素级别(=人员)有1个观察值。

    1b。我的数据每个因素级别(=组)有多个观察值。

  2. 平均值比较

    2a.您使用FSA::Dunntest来拟合模型,并立即比较每个因素级别的平均值。

    2b。我用lm()定义了一个模型,然后emmeans::emmeans()比较了每个因素水平的平均值。

  3. 紧凑字母显示

    3a.您使用rcompanion::cldList()获取信件。

    3b.我使用multcomp::cld()获取信件。

我认为第2点和第3点完全没问题--只是不同的功能导致了相同的目标。我在我的数据上尝试了您的方法,它起作用了:

dunnTest_out <- FSA::dunnTest(weight ~ as.factor(group), method = "bh", data = PlantGrowth)
rcompanion::cldList(P.adj ~ Comparison, data = dunnTest_out$res, threshold = 0.05)
#>   Group Letter MonoLetter
#> 1  ctrl     ab         ab
#> 2  trt1      a         a 
#> 3  trt2      b          b

然而,在我看来,您的数据似乎是错误的。如果您的&均值不是实际均值,而是单个值,则不能相互比较,甚至不能执行测试(其结果可以通过紧凑的字母显示屏显示)。

我将您的示例简化为以下数据集之一:

dat_1.1.B <- 
  tibble::tribble(
    ~Person, ~Height, ~Weight,
    "Luke",    177,     66,
    "Alex",    169,     69,
    "Haley",    145,    54
  )

dunnTest_out <- FSA::dunnTest(Weight ~ as.factor(Person), method = "bh", data = dat_1.1.B)
dunnTest_out
#> Dunn (1964) Kruskal-Wallis multiple comparison
#>   p-values adjusted with the Benjamini-Hochberg method.
#>     Comparison          Z   P.unadj     P.adj
#> 1 Alex - Haley  1.4142136 0.1572992 0.4718976
#> 2  Alex - Luke  0.7071068 0.4795001 0.4795001
#> 3 Haley - Luke -0.7071068 0.4795001 0.7192502

rcompanion::cldList(P.adj ~ Comparison, data = dunnTest_out$res, threshold = 0.05)
#> Error: No significant differences.

请注意,当我将其中一个Weight值更改为一个大得多的数字,但p值根本不变时,情况变得非常明显,有些东西不能正常工作。

dat_1.1.B <- 
  tibble::tribble(
    ~Person, ~Height, ~Weight,
    "Luke",    177,     66,
    "Alex",    169,     100000069,
    "Haley",    145,     54
  )

dunnTest_out <- FSA::dunnTest(Weight ~ as.factor(Person), method = "bh", data = dat_1.1.B)
dunnTest_out
#> Dunn (1964) Kruskal-Wallis multiple comparison
#>   p-values adjusted with the Benjamini-Hochberg method.
#>     Comparison          Z   P.unadj     P.adj
#> 1 Alex - Haley  1.4142136 0.1572992 0.4718976
#> 2  Alex - Luke  0.7071068 0.4795001 0.4795001
#> 3 Haley - Luke -0.7071068 0.4795001 0.7192502

rcompanion::cldList(P.adj ~ Comparison, data = dunnTest_out$res, threshold = 0.05)
#> Error: No significant differences.

所以,是的,我认为是数据的问题。请注意,错误&没有显著差异&对我来说也很奇怪,因为假设测试正确完成,没有显著差异只是意味着所有值的字母都相同。

Dr:数据才是问题所在。如果您的平均值仅为每个组的单个值,则不能通过测试比较平均值。如果您有用于获取每个组的单个值的原始数据,则应将其输入到您的模型中-就像我的示例以及?FSA::Dunntest?rcompanion::cldList()的示例中所做的那样。

这篇关于如何将紧凑型字母显示添加到ggboxlot()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆