在分面 ggviolin 图中缺少 P 值(R,ggplot2)。

huangapple go评论71阅读模式
英文:

P values missing in faceted ggviolin plot (R, ggplot2)

问题

我有这段代码:

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没有数据,但如何让它显示出来呢?重要的是,我的真实数据有更多的分面,所以我希望找到一个适用于所有分面的解决方案,而不是对特定分面进行调整,我已经找到了解决方案。谢谢。

英文:

I have this code:

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

In the first facet, the p value comparing grp1 and grp2 is missing, although it can be calculated. I think this is because grp3 has no data, but how can I get it to show up? Importantly, my real data have many more facets, so I would like a solution that works across facets rather than making adjustments to specific facets, which I have found solutions for. Thank you.

答案1

得分: 1

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

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"
  )

在分面 ggviolin 图中缺少 P 值(R,ggplot2)。

英文:

Not sure if this answers your question. It shows the missing comparisons.

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

在分面 ggviolin 图中缺少 P 值(R,ggplot2)。

huangapple
  • 本文由 发表于 2023年2月16日 09:07:26
  • 转载请务必保留本文链接:https://go.coder-hub.com/75466881.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定