Seurat 中的数据可视化方法

简介: Seurat 中的数据可视化方法

本文将使用从 2,700 PBMC 教程计算的 Seurat 对象来演示 Seurat 中的可视化技术。您可以从 SeuratData 下载此数据集。

SeuratData::InstallData("pbmc3k")

library(Seurat)
library(SeuratData)
library(ggplot2)
library(patchwork)
pbmc3k.final <- LoadData("pbmc3k", type = "pbmc3k.final")
pbmc3k.final$groups <- sample(c("group1", "group2"), size = ncol(pbmc3k.final), replace = TRUE)
features <- c("LYZ", "CCL5", "IL32", "PTPRCAP", "FCGR3A", "PF4")
pbmc3k.final
## An object of class Seurat 
## 13714 features across 2638 samples within 1 assay 
## Active assay: RNA (13714 features, 2000 variable features)
##  3 layers present: data, counts, scale.data
##  2 dimensional reductions calculated: pca, umap

marker 特征表达的五种可视化

1. RidgePlot

# Ridge plots - from ggridges. Visualize single cell expression distributions in each cluster
RidgePlot(pbmc3k.final, features = features, ncol = 2)

2. VlnPlot

# Violin plot - Visualize single cell expression distributions in each cluster
VlnPlot(pbmc3k.final, features = features)

# Violin plots can also be split on some variable. Simply add the splitting variable to object
# metadata and pass it to the split.by argument
VlnPlot(pbmc3k.final, features = "percent.mt", split.by = "groups")

3. FeaturePlot

# Feature plot - visualize feature expression in low-dimensional space
FeaturePlot(pbmc3k.final, features = features)

# Plot a legend to map colors to expression levels
FeaturePlot(pbmc3k.final, features = "MS4A1")

# Adjust the contrast in the plot
FeaturePlot(pbmc3k.final, features = "MS4A1", min.cutoff = 1, max.cutoff = 3)

# Calculate feature-specific contrast levels based on quantiles of non-zero expression.
# Particularly useful when plotting multiple markers
FeaturePlot(pbmc3k.final, features = c("MS4A1", "PTPRCAP"), min.cutoff = "q10", max.cutoff = "q90")

# Visualize co-expression of two features simultaneously
FeaturePlot(pbmc3k.final, features = c("MS4A1", "CD79A"), blend = TRUE)

img

# Split visualization to view expression by groups (replaces FeatureHeatmap)
FeaturePlot(pbmc3k.final, features = c("MS4A1", "CD79A"), split.by = "groups")

4. DotPlot

# Dot plots - the size of the dot corresponds to the percentage of cells expressing the
# feature in each cluster. The color represents the average expression level
DotPlot(pbmc3k.final, features = features) + RotatedAxis()

# SplitDotPlotGG has been replaced with the `split.by` parameter for DotPlot
DotPlot(pbmc3k.final, features = features, split.by = "groups") + RotatedAxis()

5. DoHeatmap

## Single cell heatmap of feature expression
DoHeatmap(subset(pbmc3k.final, downsample = 100), features = features, size = 3)

新绘图函数

DimPlot

# DimPlot replaces TSNEPlot, PCAPlot, etc. In addition, it will plot either 'umap', 'tsne', or
# 'pca' by default, in that order
DimPlot(pbmc3k.final)

pbmc3k.final.no.umap <- pbmc3k.final
pbmc3k.final.no.umap[["umap"]] <- NULL
DimPlot(pbmc3k.final.no.umap) + RotatedAxis()

DoHeatmap

# DoHeatmap now shows a grouping bar, splitting the heatmap into groups or clusters. This can
# be changed with the `group.by` parameter
DoHeatmap(pbmc3k.final, features = VariableFeatures(pbmc3k.final)[1:100], cells = 1:500, size = 4,
    angle = 90) + NoLegend()

将主题应用于绘图

使用 Seurat,所有绘图函数默认返回基于 ggplot2 的绘图,允许人们像任何其他基于 ggplot2 的绘图一样轻松捕获和操作绘图。

baseplot <- DimPlot(pbmc3k.final, reduction = "umap")
# Add custom labels and titles
baseplot + labs(title = "Clustering of 2,700 PBMCs")

# Use community-created themes, overwriting the default Seurat-applied theme Install ggmin
# with remotes::install_github('sjessa/ggmin')
baseplot + ggmin::theme_powerpoint()

# Seurat also provides several built-in themes, such as DarkTheme; for more details see
# ?SeuratTheme
baseplot + DarkTheme()

# Chain themes together
baseplot + FontSize(x.title = 20, y.title = 20) + NoLegend()

交互式绘图功能

Seurat 利用 R 的绘图库来创建交互式绘图。此交互式绘图功能适用于任何基于 ggplot2 的散点图(需要 geom_point 图层)。使用时,只需制作一个基于 ggplot2 的散点图(例如 DimPlot() 或 FeaturePlot())并将结果图传递给 HoverLocator()

# Include additional data to display alongside cell names by passing in a data frame of
# information.  Works well when using FetchData
plot <- FeaturePlot(pbmc3k.final, features = "MS4A1")
HoverLocator(plot = plot, information = FetchData(pbmc3k.final, vars = c("ident", "PC_1", "nFeature_RNA")))

Seurat 提供的另一个交互功能是能够手动选择细胞以进行进一步研究。我们发现这对于小簇特别有用,这些小簇并不总是使用无偏聚类来分离,但看起来却截然不同。现在,您可以通过创建基于 ggplot2 的散点图(例如使用 DimPlot() 或 FeaturePlot(),并将返回的图传递给 CellSelector() 来选择这些单元格。CellSelector() 将返回一个包含所选点名称的向量,这样您就可以将它们设置为新的身份类并执行微分表达式。

例如,假设 DC 在聚类中与单核细胞合并,但我们想根据它们在 tSNE 图中的位置来了解它们的独特之处。

pbmc3k.final <- RenameIdents(pbmc3k.final, DC = "CD14+ Mono")
plot <- DimPlot(pbmc3k.final, reduction = "umap")
select.cells <- CellSelector(plot = plot)

绘图配件

除了为绘图添加交互功能的新函数之外,Seurat 还提供了用于操作和组合绘图的新辅助功能。

# LabelClusters and LabelPoints will label clusters (a coloring variable) or individual points
# on a ggplot2-based scatter plot
plot <- DimPlot(pbmc3k.final, reduction = "pca") + NoLegend()
LabelClusters(plot = plot, id = "ident")

# Both functions support `repel`, which will intelligently stagger labels and draw connecting
# lines from the labels to the points or clusters
LabelPoints(plot = plot, points = TopCells(object = pbmc3k.final[["pca"]]), repel = TRUE)

绘制多个图之前是通过CombinePlot() 函数实现的。我们不赞成使用此功能,转而使用拼凑系统。下面是一个简短的演示,但请参阅此处的 patchwork 包网站以获取更多详细信息和示例。

plot1 <- DimPlot(pbmc3k.final)
# Create scatter plot with the Pearson correlation value as the title
plot2 <- FeatureScatter(pbmc3k.final, feature1 = "LYZ", feature2 = "CCL5")
# Combine two plots
plot1 + plot2

# Remove the legend from all plots
(plot1 + plot2) & NoLegend()

相关文章
|
传感器 人工智能 监控
智慧电厂AI算法方案
智慧电厂AI算法方案通过深度学习和机器学习技术,实现设备故障预测、发电运行优化、安全监控和环保管理。方案涵盖平台层、展现层、应用层和基础层,具备精准诊断、智能优化、全方位监控等优势,助力电厂提升效率、降低成本、保障安全和环保合规。
938 2
智慧电厂AI算法方案
|
8月前
|
数据采集 大数据 测试技术
Python列表推导式实战:1-100偶数生成全解析
列表推导式是Python中简洁高效的语法糖,可一行代码替代传统循环,用于生成、筛选和转换列表。相比常规写法更优雅且性能更优,适用于逻辑清晰的场景,但复杂嵌套时需注意可读性。
363 0
|
API 监控 双11
淘宝/天猫获取商品历史价格信息 API 返回值的应用
本内容介绍了一款基于API的工具的核心功能,涵盖消费者决策支持、商家运营优化、市场趋势分析及数据服务拓展四大方面。消费者可借助历史价格曲线判断价格合理性、选择最佳购买时机;商家可通过竞品数据分析优化定价策略与促销活动;第三方平台能监测价格波动、跟踪竞品动态以洞察市场趋势。此外,工具还支持比价工具开发与价格预警服务,为用户和企业带来全方位的价格智能解决方案。
|
数据可视化 数据库
scRNA分析|使用CellChat完成细胞通讯分析-简单且可视化出众,代码自取
scRNA分析|使用CellChat完成细胞通讯分析-简单且可视化出众,代码自取
3913 1
|
应用服务中间件 网络安全 Apache
学校/教育单位申请免费SSL证书
学校或教育单位可通过JoySSL申请免费SSL证书。访问JoySSL官网注册账号,填写特定注册码230922获取申请资格,选择适合的免费一年期SSL证书并完成验证。需确保域名与IP地址正确,定期检查和更新证书,正确安装配置,确保安全性和兼容性,符合合规要求。如有问题,可联系技术支持。
|
分布式计算 监控 数据挖掘
云上游戏数据分析实践
数据分析和游戏的生命周期与盈利息息相关,同时数据分析对游戏的运维也起到了至关重要的作用,精确的数据分析可以延长游戏的生命和帮助其盈利。本文针对游戏行业的数据特点,结合游戏数据分析的现状,对数据分析上云的技术选型、结合数加大数据计算服务MaxCompute(原ODPS)、SLS、RDS、DPC等产品和
6297 0
|
运维 监控 KVM
什么是带内管理 带外管理?(转)
什么叫带外管理?常见的设备管理方式有SNMP、RMON、Web、TELNET以及通过CONSOLE、AUX接口管理,有些高端设备还具备100BASE-TX的带外管理端口。我在网上查到大概SNMP、RMON、Web、TELNET这些管理方式属于带内管理,通过CONSOLE、AUX接口管理和通过某些高端设备具有的100BASE-TX的带外管理端口进行管理的方式属于带外管理。
3449 0
|
Java 数据挖掘 Go
JCR一区7.7分|单细胞联合bulk-seq的线粒体自噬,分析方法都挺好
这篇文章介绍了研究者通过分析单细胞和Bulk RNA测序数据,鉴定出18个与胃癌(GC)进展相关的线粒体自噬相关基因(MRG),并建立了基于这些基因的预后模型。研究发现GABARAPL2和CDC37可能是GC的预后标志物和潜在治疗靶点。此外,分析揭示了细胞间通讯模式和免疫浸润状态,暗示MRG可能影响GC的免疫治疗响应。整体而言,这项工作为GC的诊断和治疗提供了新见解。
700 0
|
人工智能 数据可视化
跟SCI学umap图| ggplot2 绘制umap图,坐标位置 ,颜色 ,大小还不是你说了算
跟SCI学umap图| ggplot2 绘制umap图,坐标位置 ,颜色 ,大小还不是你说了算
2586 1
|
Windows
【无需格式化硬盘即可C盘扩容以及新建磁盘】
【无需格式化硬盘即可C盘扩容以及新建磁盘】
1633 1
【无需格式化硬盘即可C盘扩容以及新建磁盘】