本期内容:👇
rm(list = ls())
library(Seurat)
library(SeuratExtend)
pbmc

genes <- c("CD3D","CD14","CD79A")
VlnPlot2(pbmc, features = genes, ncol = 1)

点随机分布!~🫠
VlnPlot2(pbmc, features = genes, violin = FALSE, pt.style = "quasirandom", ncol = 1)

不显示点!~😀
VlnPlot2(pbmc, features = genes, pt = FALSE, ncol = 1)

不显示outlier!~😅
VlnPlot2(pbmc, features = genes, pt = FALSE, hide.outlier = TRUE, ncol = 1)

VlnPlot2(pbmc, features = genes, style = "outline", ncol = 1)

lowExprGenes <- c("CCR7", "IL7R", "TCF7")
VlnPlot2(pbmc,
features = lowExprGenes,
show.mean = TRUE, # Show mean and median lines
mean_colors = c("red", "blue"), # Colors for mean and median
cols = "light", # Light color scheme for better visibility
ncol = 1)

VlnPlot2(pbmc, features = genes, group.by = "cluster", split.by = "orig.ident")

cells <- colnames(pbmc)[pbmc$cluster %in% c("B cell", "Mono CD14", "CD8 T cell")]
VlnPlot2(pbmc, features = genes, group.by = "cluster", cells = cells)

wilcox.test!~
VlnPlot2(pbmc,
features = genes,
group.by = "cluster",
cells = cells,
stat.method = "wilcox.test",
hide.ns = TRUE)

t.test!~
VlnPlot2(pbmc,
features = genes,
group.by = "cluster",
cells = cells,
stat.method = "t.test",
comparisons = list(c(1,2), c(1,3)),
hide.ns = FALSE)

这里我们把基因集富集分析的AUCell分数作为输入文件。😘
# Perform gene set analysis
pbmc <- GeneSetAnalysis(pbmc, genesets = hall50$human)
matr <- pbmc@misc$AUCell$genesets
# Plot the first three pathways
VlnPlot2(matr[1:3,], f = pbmc$cluster, ncol = 1)

ClusterDistrBar(origin = pbmc$orig.ident, cluster = pbmc$cluster)

ClusterDistrBar(origin = pbmc$orig.ident, cluster = pbmc$cluster, percent = FALSE)

ClusterDistrBar(origin = pbmc$orig.ident, cluster = pbmc$cluster, flip = FALSE, reverse_order = FALSE)

ClusterDistrBar(origin = pbmc$orig.ident,
cluster = pbmc$cluster,
flip = FALSE,
stack = FALSE)

ClusterDistrBar(origin = pbmc$orig.ident, cluster = pbmc$cluster, rev = TRUE, normalize = TRUE)

# Compare cluster distribution between conditions
ClusterDistrPlot(
origin = pbmc$sample_id,
cluster = pbmc$cluster,
condition = pbmc$condition
)

pbmc <- GeneSetAnalysis(pbmc, genesets = hall50$human)
matr <- pbmc@misc$AUCell$genesets
WaterfallPlot(matr, f = pbmc$cluster, ident.1 = "Mono CD14", ident.2 = "CD8 T cell")

# Create a plot using the new segment style
WaterfallPlot(
matr,
f = pbmc$cluster,
ident.1 = "Mono CD14",
ident.2 = "CD8 T cell",
style = "segment",
color_theme = "D"
)

WaterfallPlot(
matr,
f = pbmc$cluster,
ident.1 = "Mono CD14",
ident.2 = "CD8 T cell",
len.threshold = 2)

genes <- VariableFeatures(pbmc)[1:70]
WaterfallPlot(
pbmc,
group.by = "cluster",
features = genes,
ident.1 = "Mono CD14",
ident.2 = "CD8 T cell",
length = "logFC")

仅显示差异表达较大的基因!~🥸
WaterfallPlot(
pbmc,
group.by = "cluster",
features = genes,
ident.1 = "Mono CD14",
ident.2 = "CD8 T cell",
length = "logFC",
top.n = 20)

使用Log2或Log10展示倍数变化。😀
# Using log base 2 for fold change calculations
WaterfallPlot(
pbmc,
group.by = "cluster",
features = genes,
ident.1 = "Mono CD14",
ident.2 = "CD8 T cell",
length = "logFC",
log.base = "2", # Use log2 instead of natural log
top.n = 20)

VolcanoPlot(pbmc,
ident.1 = "B cell",
ident.2 = "CD8 T cell")

VolcanoPlot(
pbmc,
ident.1 = "B cell",
ident.2 = "CD8 T cell",
x.threshold = 0.5, # Log fold change threshold
y.threshold = 2 # -log10(p-value) threshold
)

在单细胞分析中使用t-scor代替p值作为y轴`特别有用。🥳
由于单细胞数据集中的细胞数量较多,p 值通常变得极其显著,导致许多基因在使用-log10(p 值)时聚集在 y 轴的顶部。🧐
这使得很难区分在技术上都非常重要的基因。🧬
t-score提供了更好的分布,并有助于创建信息更丰富的可视化效果。🙊
VolcanoPlot(
pbmc,
ident.1 = "B cell",
ident.2 = "CD8 T cell",
y = "tscore"
)

VolcanoPlot(
pbmc,
ident.1 = "B cell",
ident.2 = "CD8 T cell",
log.base = "2" # Use log2 instead of natural log
)

# Using the previously calculated pathway enrichment scores
VolcanoPlot(
matr,
f = pbmc$cluster,
ident.1 = "B cell",
ident.2 = "Mono CD14",
x.quantile = 0.8,
y.quantile = 0.8,
top.n = 5)
