分面ggviolin图中缺失P值(R,ggplot2)

6l7fqoea  于 2023-02-17  发布在  其他
关注(0)|答案(1)|浏览(146)

我有这个代码:

library(ggplot2)
 library(ggpubr)
 df <- ToothGrowth
 df$dose <- as.factor(df$dose)
 df$group <- c(rep(c("grp1", "grp2"), 5), rep(c("grp1", "grp2", "grp3"), 6), 
           rep(c("grp1", "grp2"), 6), rep(c("grp1", "grp2", "grp3"), 6), "grp2", "grp3")
 plot <- ggviolin(df, x = "group", y = "len", fill = "group",
                  width = 0.8, alpha = 0.5, draw_quantiles = c(0.25, 0.5, 0.75), facet.by = 'dose') +
          scale_fill_manual(values = c("#00AFBB", "#E7B800", "#FC4E07")) + 
          stat_compare_means(comparisons = list(c("grp1","grp2"),c("grp2","grp3")), 
                  label = "p.format")

在第一个方面,比较grp1和grp2的p值缺失,尽管可以计算它。我认为这是因为grp3没有数据,但我如何才能显示它呢?重要的是,我的真实的数据有更多方面,所以我希望解决方案能够跨方面工作,而不是对特定方面进行调整,我已经找到了解决方案。谢谢。

wgmfuz8q

wgmfuz8q1#

不确定这是否回答了您的问题。它显示了缺失的比较。

plot <- ggviolin(df,
  x = "group", y = "len", fill = "group",
  width = 0.8, alpha = 0.5, draw_quantiles = c(0.25, 0.5, 0.75), facet.by = "dose"
) +
  scale_fill_manual(values = c("#00AFBB", "#E7B800", "#FC4E07")) +
  stat_compare_means(
    comparisons = list(c("grp1", "grp2"), c("grp2", "grp3")),
    label = "p.format"
  ) +
  stat_compare_means(
    comparisons = list(c("grp1", "grp2")),
    label = "p.format"
  )

相关问题