在seurat中向小提琴图添加p值

kmpatx3s  于 2023-01-15  发布在  其他
关注(0)|答案(1)|浏览(1076)

我目前有一个seurat对象scData,我在其中应用了使用AddModuleScore计分的模块。
AddModuleScore(scData, features = inflam, name = "inflam_score", seed = 1, search = FALSE, assay = NULL, nbin = 21, ctrl = 100, pool = NULL)
我已经画了一个小提琴图,通过这样做来看到一个视觉效果:VlnPlot(scData, features = c("inflam_score1"), pt.size = 0) + NoLegend() + theme(axis.text.x = element_text(angle = 90, hjust = 1))
是否有办法将p值添加到输出中?
我试过:
VlnPlot(scData, features = c("inflam_score1"), pt.size = 0) + stat_compare_means()
但得到这个错误:
Error in stat_compare_means() : could not find function "stat_compare_means"
我试过:
VlnPlot(scData, features = c("inflam_score1"), pt.size = 0) + stat_compare_means()
但得到这个错误:
Error in stat_compare_means() : could not find function "stat_compare_means"
更新:
我需要加载ggpubr包以获得p值。
但是,由于我有超过2对,我将如何添加全局p值加上超过2组的p值。[![在此处输入图像描述][1]][1]
我试过:

my_comparisons <- list( c("hIgG2_mIgG2", "NIS793_mIgG2"), c("hIgG2_aIL_1b", "NIS793_aIL_1b"))
VlnPlot(fib_395, features = c("trans_score1"), pt.size = 0) + stat_compare_means(comparisons = my_comparisons) + stat_compare_means()

但我收到了警告,没有显示p值:

Warning: Removed 6 rows containing missing values (geom_signif).
szqfcxe2

szqfcxe21#

更新日期:

您的错误很可能与y轴限制有关。VlnPlot()函数为绘图分配了“正确”的空间量,但您想在小提琴上方添加p值,而这些值不“适合"可用空间。如果您通过更改ylim()来增加可用空间,则它应该按预期工作:
最小可重现示例:

library(tidyverse)
library(Seurat)
#> Attaching SeuratObject
library(SeuratObject)
library(ggsignif)
library(ggpubr)

#data(package = "Seurat")
#data(package = "SeuratObject")

data(pbmc_small)

scData <- pbmc_small

cd_features <- list(c(
  'CD79B',
  'CD79A',
  'CD19',
  'CD180',
  'CD200',
  'CD3D',
  'CD2',
  'CD3E',
  'CD7',
  'CD8A',
  'CD14',
  'CD1C',
  'CD68',
  'CD9',
  'CD247'
))

AddModuleScore(object = scData, features = cd_features, name = "cd_features",
               seed = 1, search = FALSE, assay = NULL,
               nbin = 21, ctrl = 5, pool = NULL)
#> An object of class Seurat 
#> 230 features across 80 samples within 1 assay 
#> Active assay: RNA (230 features, 20 variable features)
#>  2 dimensional reductions calculated: pca, tsne

my_comparisons <- list( c("0", "1"), c("1", "2"), c("0", "2"))

VlnPlot(scData, features = "PC_1", pt.size = 0) +
  NoLegend() +
  theme(axis.text.x = element_text(angle = 90, hjust = 1)) +
  stat_compare_means()

重现问题:

VlnPlot(scData, features = "PC_1", pt.size = 0) +
  NoLegend() +
  theme(axis.text.x = element_text(angle = 90, hjust = 1)) +
  stat_compare_means(comparisons = my_comparisons)
#> [1] FALSE
#> Warning: Removed 9 rows containing missing values (`geom_signif()`).

更改ylim()以解决问题:

VlnPlot(scData, features = "PC_1", pt.size = 0) +
  NoLegend() +
  theme(axis.text.x = element_text(angle = 90, hjust = 1)) +
  stat_compare_means(comparisons = my_comparisons) +
  ylim(-2, 15)
#> [1] FALSE
#> Scale for y is already present.
#> Adding another scale for y, which will replace the existing scale.

使用ggsignif包(ggpubr使用“under the hood”)也有同样的结果:

VlnPlot(scData, features = "PC_1", pt.size = 0) +
  NoLegend() +
  theme(axis.text.x = element_text(angle = 90, hjust = 1)) +
  geom_signif(comparisons = my_comparisons,
              map_signif_level = function(p) sprintf("*p = %.2g", p),
              step_increase = 0.15) +
  ylim(-2, 15)
#> Scale for y is already present.
#> Adding another scale for y, which will replace the existing scale.

创建于2023年1月13日,使用reprex v2.0.2

相关问题