使用 geom_pwc、stat_pvalue_manual 或 stat_compare_means 在 R 中隐藏 NS 显着性和括号

问题描述 投票:0回答:1

我面临

stat_compare_means
geom_pwc
stat_pvalue_manual
的问题。问题如下:

  1. stat_compare_means
    实际上在大多数情况下都能正常工作,除了我似乎无法摆脱 NS 意义的括号这一事实。
    hide.ns
    只去掉了标签本身,但没有去掉括号,而且我似乎无法让这些括号不出现。

  2. 对于

    geom_pwc
    stat_pvalue_manual
    ,我读到
    hide.ns
    也隐藏了括号。然而,当我将这些函数中的任何一个与
    hide.ns=TRUE
    一起使用时,我的所有意义都被删除(尽管并非全部都是 ns)。

我的数据是具有三个相关变量的 df:意愿(y 轴)、性别(x 轴)和风险(facet)。我的情节是箱线图。共有三个方面(风险:0.1%、2% 和 10%)、四个性别类别(男性、女性、非二元性别和一般),意愿是一个连续的 0-100 等级。 “一般”性别只是其他三个性别类别的综合数据,以观察非特定性别的总体趋势,不应进行统计比较。

我的代码如下:

ggboxplot(combined_data,x = "gender", y = "willingness", color = "black", fill="gender", palette = c("coral4","#BBD1EA","#FFBB99","#FFF6BD"), facet.by = "Risk", short.panel.labs = FALSE, outlier.shape = NA) +
geom_point(aes(x=gender,y=willingness,fill=gender),position=position_jitterdodge(),alpha=0.3,size=1,shape=20) + 
theme(axis.text.x = element_text(angle = 45, vjust = 1, hjust=1)) + 
theme(legend.position="none", axis.text.x=element_blank(),axis.ticks.x=element_blank(),axis.title.x = element_blank()) + 
stat_compare_means(comparisons = my_comparisons, label="p.signif", hide.ns = TRUE)

stat_compare_means
中,“my_comparisons”是:

my_comparisons <- list(c("Men", "Women"), c("Men", "Non-binary"), c("Women", "Non-binary"))

这将生成下面所附的第一张图像。

当我尝试使用

geom_pwc
stat_pvalue_manual
时,它们都会产生相同的图形。注意:这个似乎不允许我指定比较,所以这里包括“一般”。如果有人知道如何指定比较,那就太好了。代码是:

ggboxplot(combined_data,x = "gender", y = "willingness", color = "black", fill="gender", palette = c("coral4","#BBD1EA","#FFBB99","#FFF6BD"), facet.by = "Risk", short.panel.labs = FALSE, outlier.shape = NA) + 
geom_point(aes(x=gender,y=willingness,fill=gender),position=position_jitterdodge(),alpha=0.3,size=1,shape=20) + 
theme(axis.text.x = element_text(angle = 45, vjust = 1, hjust=1)) + 
theme(legend.position="none", axis.text.x=element_blank(),axis.ticks.x=element_blank(),axis.title.x = element_blank()) + 
geom_pwc(group.by="x.var",label="p.signif",hide.ns=TRUE)

下图是这样的。

这就是

hide.ns=false
的样子,注意当前的显着性水平:

使用

stat_pvalue_manual
会产生与
geom_pwc
相同的结果,请注意以下代码:

stat.test <- compare_means(willingness ~ gender, data = combined_data, 
              group.by = "Risk")
ggboxplot(.......same as above) + 
stat_pvalue_manual(stat.test, label = "p.signif", hide.ns = TRUE)

因此,如果有人可以提供帮助:

  1. 使用 stat_compare_means 删除 ns 括号,或者
  2. 指定比较并修复
    hide.ns
    geom_pwc
    stat_pvalue_manual
  3. 问题

我真的很感激。谢谢!

r ggplot2 p-value ggpubr rstatix
1个回答
0
投票

您可以在绘图之前自动计算 p 值,并根据该值决定比较。在我的例子中,stat_compare_means usus wilcoxin,所以我使用 seurat findMarkers,它很快并且也有 wilcoxin。就像我的例子一样:

comparisonsi <- list(c("AL", "DR"), c("AL", "SR100"))

pval_AL_vs_DR <- FindMarkers(sne_subset, ident.1 = "AL", ident.2 = "DR", features = c(gene), min.pct = 0, logfc.threshold = 0)[gene, "p_val"]
pval_AL_vs_SR100 <- FindMarkers(sne_subset, ident.1 = "AL", ident.2 = "SR100", features = c(gene), min.pct = 0, logfc.threshold = 0)[gene, "p_val"]

if (pval_AL_vs_DR<=0.05 & pval_AL_vs_SR100<=0.05) {comparisonsi <- list(c("AL", "DR"), c("AL", "SR100"))}
if (pval_AL_vs_DR<=0.05 & pval_AL_vs_SR100>0.05) {comparisonsi <- list(c("AL", "DR"))}
if (pval_AL_vs_DR>0.05 & pval_AL_vs_SR100<=0.05) {comparisonsi <- list(c("AL", "SR100"))}
if (pval_AL_vs_DR>0.05 & pval_AL_vs_SR100>0.05) {comparisonsi <- list()}
    
    
p_violin <- VlnPlot(sne_subset, features = gene, group.by = "diet", pt.size = 0, log = T) + 
stat_compare_means(comparisons = comparisonsi, method = "wilcox.test", label = "p.signif", hide.ns = T)
© www.soinside.com 2019 - 2024. All rights reserved.