Seurat包学习笔记(十):New data visualization methods in v3.0

本教程中,我们将学习使用Seurat包进行数据可视化的常用方法。

image

加载所需的R包和数据集

library(Seurat)
library(ggplot2)
library(patchwork)
# 这里我们依旧使用之前分析过的PBMC的数据集
pbmc <- readRDS(file = "../data/pbmc3k_final.rds")
# 添加分组信息
pbmc$groups <- sample(c("group1", "group2"), size = ncol(pbmc), replace = TRUE)
pbmc
## An object of class Seurat 
## 13714 features across 2638 samples within 1 assay 
## Active assay: RNA (13714 features)
##  2 dimensional reductions calculated: pca, umap

# 选定用于可视化的marker基因
features <- c("LYZ", "CCL5", "IL32", "PTPRCAP", "FCGR3A", "PF4")

五种常规的Marker基因表达可视化类型

# Ridge plots - from ggridges. Visualize single cell expression distributions in each cluster
# 峰峦图(RidgePlot)可视化marker基因的表达
RidgePlot(pbmc, features = features, ncol = 2)
image
# Violin plot - Visualize single cell expression distributions in each cluster
# 小提琴图(VlnPlot)可视化marker基因的表达
VlnPlot(pbmc, features = features)
image
# Feature plot - visualize feature expression in low-dimensional space
# 散点图(FeaturePlot)可视化marker基因的表达
FeaturePlot(pbmc, features = features)
image
# 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)可视化marker基因的表达
DotPlot(pbmc, features = features) + RotatedAxis()
image
# Single cell heatmap of feature expression
# 热图(DoHeatmap)可视化marker基因的表达
DoHeatmap(subset(pbmc, downsample = 100), features = features, size = 3)
image

New additions to FeaturePlot

# Plot a legend to map colors to expression levels
FeaturePlot(pbmc, features = "MS4A1")
image
# Adjust the contrast in the plot
# 使用min.cutoff = 1, max.cutoff = 3参数调整图例的范围
FeaturePlot(pbmc, features = "MS4A1", min.cutoff = 1, max.cutoff = 3)
image
# Calculate feature-specific contrast levels based on quantiles of non-zero expression.
# Particularly useful when plotting multiple markers
FeaturePlot(pbmc, features = c("MS4A1", "PTPRCAP"), min.cutoff = "q10", max.cutoff = "q90")
image
# Visualize co-expression of two features simultaneously
FeaturePlot(pbmc, features = c("MS4A1", "CD79A"), blend = TRUE)
image
# Split visualization to view expression by groups (replaces FeatureHeatmap)
FeaturePlot(pbmc, features = c("MS4A1", "CD79A"), split.by = "groups")
image

Updated and expanded visualization functions

In addition to changes to FeaturePlot, several other plotting functions have been updated and expanded with new features and taking over the role of now-deprecated functions

# 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(pbmc, features = "percent.mt", split.by = "groups")
image
# SplitDotPlotGG has been replaced with the `split.by` parameter for DotPlot
DotPlot(pbmc, features = features, split.by = "groups") + RotatedAxis()
image
# DimPlot replaces TSNEPlot, PCAPlot, etc. In addition, it will plot either 'umap', 'tsne', or 'pca' by default, in that order
DimPlot(pbmc)
image
pbmc.no.umap <- pbmc
pbmc.no.umap[["umap"]] <- NULL
DimPlot(pbmc.no.umap) + RotatedAxis()
image
# DoHeatmap now shows a grouping bar, splitting the heatmap into groups or clusters. This can be changed with the `group.by` parameter
DoHeatmap(pbmc, features = VariableFeatures(pbmc)[1:100], cells = 1:500, size = 4, angle = 90) + NoLegend()
image

Applying themes to plots

With Seurat v3.0, all plotting functions return ggplot2-based plots by default, allowing one to easily capture and manipulate plots just like any other ggplot2-based plot.

baseplot <- DimPlot(pbmc, reduction = "umap")
# Add custom labels and titles
# 添加标题
baseplot + labs(title = "Clustering of 2,700 PBMCs")
image
# Use community-created themes, overwriting the default Seurat-applied theme Install ggmin with devtools::install_github('sjessa/ggmin')
# 更换图片背景主题为theme_powerpoint()
baseplot + ggmin::theme_powerpoint()
image
# Seurat also provides several built-in themes, such as DarkTheme; for more details see ?SeuratTheme
# 更换图片背景主题为Seurat自带的DarkTheme()
baseplot + DarkTheme()
image
# Chain themes together
# 调整坐标轴字体大小
baseplot + FontSize(x.title = 20, y.title = 20) + NoLegend()
image

Interactive plotting features 交互式可视化

Seurat调用R的plotly包进行交互式可视化,这种交互式特性可以用于任何基于ggplot2散点图绘制的图形(需要使用geom_point图层)。在Seurat中,我们可以使用HoverLocator函数对基于ggplot2散点图可视化的函数(如DimPlotFeaturePlot)进行交互式可视化处理。

# Include additional data to display alongside cell names by passing in a data frame of information Works well when using FetchData
plot <- FeaturePlot(pbmc, features = "MS4A1")
# 使用information参数设置想要展示的数据类型
HoverLocator(plot = plot, information = FetchData(pbmc, vars = c("ident", "PC_1", "nFeature_RNA")))
image

Seurat提供的另一个交互式功能是能够手动选择一些细胞以进行进一步的研究。我们可以通过CellSelector函数对已经创建好的基于ggplot2散点图绘制的图形(如DimPlot或FeaturePlot)选择想要的细胞所在的点。CellSelector将返回一个包含所选的点对应的细胞名称的向量,这样我们就可以对这些细胞重新命名为一个群体,并对其进行差异表达分析。

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

然后,我们可以使用SetIdent函数将选定的细胞设定成一个新的小型类群。

head(select.cells)
## [1] "AAGATTACCGCCTT" "AAGCCATGAACTGC" "AATTACGAATTCCT" "ACCCGTTGCTTCTA"
## [5] "ACGAGGGACAGGAG" "ACGTGATGCCATGA"
Idents(pbmc, cells = select.cells) <- "NewCells"

# Now, we find markers that are specific to the new cells, and find clear DC markers
newcells.markers <- FindMarkers(pbmc, ident.1 = "NewCells", ident.2 = "CD14+ Mono", min.diff.pct = 0.3, only.pos = TRUE)
head(newcells.markers)
image

使用CellSelector手动的命名细胞类群

除了返回所选定细胞的名称组成的向量外,CellSelector还可以获取选定的细胞并为其分配新的标识,返回一个具有新设置标识的Seurat对象。例如,我们选择与之前相同的一组细胞,并将其重新标识为“ selected”类。

pbmc <- CellSelector(plot = plot, object = pbmc, ident = "selected")
image
levels(pbmc)
## [1] "selected"     "Naive CD4 T"  "Memory CD4 T" "CD14+ Mono"   "B"           
## [6] "CD8 T"        "FCGR3A+ Mono" "NK"           "Platelet"

Plotting Accessories 绘图配件

除了增加的一些新功能和交互式可视化之外,Seurat还提供了一些用于处理和合并图像的新附件功能。
使用LabelClusters函数添加分群的类名

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

使用LabelPoints函数添加指定细胞的名称

# 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 = pbmc[["pca"]]), repel = TRUE)
image

尽管CombinePlot函数可以将多个图形绘制在一起,但我们不赞成使用此功能,而建议使用pathwork包的组合图功能。

plot1 <- DimPlot(pbmc)
plot2 <- FeatureScatter(pbmc, feature1 = "LYZ", feature2 = "CCL5")
# Combine two plots
plot1 + plot2
image
# Remove the legend from all plots
(plot1 + plot2) & NoLegend()
image

参考来源:https://satijalab.org/seurat/v3.1/visualization_vignette.html

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 205,386评论 6 479
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 87,939评论 2 381
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 151,851评论 0 341
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 54,953评论 1 278
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 63,971评论 5 369
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,784评论 1 283
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 38,126评论 3 399
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,765评论 0 258
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 43,148评论 1 300
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,744评论 2 323
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,858评论 1 333
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,479评论 4 322
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 39,080评论 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 30,053评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,278评论 1 260
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 45,245评论 2 352
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,590评论 2 343

推荐阅读更多精彩内容