Visualization

여기서는 이미 2,700 PBMC 튜토리얼에서 나온 Seurat 객체로 visualization 기술들을 보여드리려고 합니다. 이 데이터세트는 SeuratData에서 다운받으실 수 있습니다.

SeuratData::InstallData("pbmc3k")
library(Seurat)
library(SeuratData)
library(ggplot2)
library(patchwork)
data("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)
##  2 dimensional reductions calculated: pca, umap

Five visualizations of marker feature expression

# Ridge plots - from ggridges. Visualize single cell expression distributions in each cluster
RidgePlot(pbmc3k.final, features = features, ncol = 2)
https://satijalab.org/seurat/articles/visualization_vignette_files/figure-html/visualization_smorgasbord-1.png
# Violin plot - Visualize single cell expression distributions in each cluster
VlnPlot(pbmc3k.final, features = features)
https://satijalab.org/seurat/articles/visualization_vignette_files/figure-html/visualization_smorgasbord-2.png
# Feature plot - visualize feature expression in low-dimensional space
FeaturePlot(pbmc3k.final, features = features)
https://satijalab.org/seurat/articles/visualization_vignette_files/figure-html/visualization_smorgasbord-3.png
# 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()
https://satijalab.org/seurat/articles/visualization_vignette_files/figure-html/visualization_smorgasbord2-1.png
# Single cell heatmap of feature expression
DoHeatmap(subset(pbmc3k.final, downsample = 100), features = features, size = 3)
https://satijalab.org/seurat/articles/visualization_vignette_files/figure-html/visualization_smorgasbord2-2.png

New additions to FeaturePlot

# Plot a legend to map colors to expression levels
FeaturePlot(pbmc3k.final, features = "MS4A1")
https://satijalab.org/seurat/articles/visualization_vignette_files/figure-html/featureplot-1.png
# Adjust the contrast in the plot
FeaturePlot(pbmc3k.final, features = "MS4A1", min.cutoff = 1, max.cutoff = 3)
https://satijalab.org/seurat/articles/visualization_vignette_files/figure-html/featureplot-2.png
# 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")
https://satijalab.org/seurat/articles/visualization_vignette_files/figure-html/featureplot2-1.png
# Visualize co-expression of two features simultaneously
FeaturePlot(pbmc3k.final, features = c("MS4A1", "CD79A"), blend = TRUE)
https://satijalab.org/seurat/articles/visualization_vignette_files/figure-html/featureplot2-2.png
# Split visualization to view expression by groups (replaces FeatureHeatmap)
FeaturePlot(pbmc3k.final, features = c("MS4A1", "CD79A"), split.by = "groups")
https://satijalab.org/seurat/articles/visualization_vignette_files/figure-html/featureplot.split-1.png

Updated and expanded visualization functions

FeaturePlot() 외에도, 몇가지 다른 plotting 함수들도 업데이트 및 확장 되어서 새로운 기능들이 지금은 사용되지 않는 기능의 역할을 대신합니다.

# 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")
https://satijalab.org/seurat/articles/visualization_vignette_files/figure-html/new_functions-1.png
# SplitDotPlotGG has been replaced with the `split.by` parameter for DotPlot
DotPlot(pbmc3k.final, features = features, split.by = "groups") + RotatedAxis()
https://satijalab.org/seurat/articles/visualization_vignette_files/figure-html/new_functions-2.png
# DimPlot replaces TSNEPlot, PCAPlot, etc. In addition, it will plot either 'umap', 'tsne', or
# 'pca' by default, in that order
DimPlot(pbmc3k.final)
https://satijalab.org/seurat/articles/visualization_vignette_files/figure-html/new_functions-3.png
pbmc3k.final.no.umap <- pbmc3k.final
pbmc3k.final.no.umap[["umap"]] <- NULL
DimPlot(pbmc3k.final.no.umap) + RotatedAxis()
https://satijalab.org/seurat/articles/visualization_vignette_files/figure-html/new_functions-4.png
# 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()
https://satijalab.org/seurat/articles/visualization_vignette_files/figure-html/new2-1.png

Applying themes to plots

Seurat 에서는 모든 plotting 함수는 기본적으로 ggplot2-based plot 을 반환합니다. 이것은 다른 ggplot2-based plot 와 마찬가지로 plot 을 쉽게 캡처하고 조작할 수 있습니다.

baseplot <- DimPlot(pbmc3k.final, reduction = "umap")
# Add custom labels and titles
baseplot + labs(title = "Clustering of 2,700 PBMCs")
https://satijalab.org/seurat/articles/visualization_vignette_files/figure-html/themeing-1.png
# Use community-created themes, overwriting the default Seurat-applied theme Install ggmin
# with remotes::install_github('sjessa/ggmin')
baseplot + ggmin::theme_powerpoint()
https://satijalab.org/seurat/articles/visualization_vignette_files/figure-html/themeing-2.png
# Seurat also provides several built-in themes, such as DarkTheme; for more details see
# ?SeuratTheme
baseplot + DarkTheme()
https://satijalab.org/seurat/articles/visualization_vignette_files/figure-html/themeing-3.png
# Chain themes together
baseplot + FontSize(x.title = 20, y.title = 20) + NoLegend()
https://satijalab.org/seurat/articles/visualization_vignette_files/figure-html/themeing-4.png

Interactive plotting features

Seurat 은 R의 plotly graphing 라이브러리를 활용하여 interactive 한 plot 을 만듭니다. 이 interactive plotting 기능은 ggplot2-based scatter plots 에서 사용하실 수 있습니다 (geom_point 레이어가 필요합니다). 이걸 하시려면, ggplot2-based scatter plot (DimPlot()FeaturePlot() 같은) 을 만들고 결과로 나오는 plot 에 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")))

**여기서 나오는 plot 은 interactive 한 plot 이라서 노션에서 보실 수 없어서 이 튜토리얼 웹사이트에서 확인하시는 것을 추천드립니다!!

Seurat 에서 제공되는 다른 interactive 한 기능으로는 세포를 수동으로 선택해서 볼 수 있는 것 입니다. 이 기능은 unbiased clustering 으로 구분이 되지 않는 작은 cluster 들에 유용합니다. 이제 ggplot2-based scatter plot (DimPlot()FeaturePlot() 같은) 을 만들어서 나온 plot 에 CellSelector() 를 실행시켜서 이러한 세포들을 고를 수 있습니다. CellSelector() 는 선택된 point 의 vector 를 반환해서 새 identity class 를 설정하고 differential expression 을 할 수 있게 합니다.

예를 들어, DCs 와 monocytes 가 섞여서 clustering 되었다고 가정해 보겠습니다. tSNE plot 에서의 위치에 따라서, 이 두 cell type 에서 unique 한게 뭐가 있는지 알아보려합니다.

pbmc3k.final <- RenameIdents(pbmc3k.final, DC = "CD14+ Mono")
plot <- DimPlot(pbmc3k.final, reduction = "umap")
select.cells <- CellSelector(plot = plot)
https://satijalab.org/seurat/articles/assets/pbmc_select.gif

그리고 이제 이 세포들의 identity 를 바꿔서 mini-cluster 로 나눌 수 있습니다.

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

# Now, we find markers that are specific to the new cells, and find clear DC markers
newcells.markers <- FindMarkers(pbmc3k.final, ident.1 = "NewCells", ident.2 = "CD14+ Mono", min.diff.pct = 0.3,
    only.pos = TRUE)
head(newcells.markers)
##                 p_val avg_log2FC pct.1 pct.2    p_val_adj
## FCER1A   3.239004e-69  3.7008561 0.800 0.017 4.441970e-65
## SERPINF1 7.761413e-36  1.5737896 0.457 0.013 1.064400e-31
## HLA-DQB2 1.721094e-34  0.9685974 0.429 0.010 2.360309e-30
## CD1C     2.304106e-33  1.7785158 0.514 0.025 3.159851e-29
## ENHO     5.099765e-32  1.3734708 0.400 0.010 6.993818e-28
## ITM2C    4.299994e-29  1.5590007 0.371 0.010 5.897012e-25

Plotting Accessories

Seurat 은 plot 를 interactive 하게 만드는 새로운 함수들과 함께, 새로운 accessory 함수들은 plot를 조작하고 결합하기 위한 기능을 제공합니다.

# 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")
https://satijalab.org/seurat/articles/visualization_vignette_files/figure-html/labelling-1.png
# 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)
https://satijalab.org/seurat/articles/visualization_vignette_files/figure-html/labelling-2.png

이전에는 CombinePlot() 함수를 이용해서 여러개의 plot 을 만들었습니다. 저희는 patchwork 시스템에 더 잘 작용되도록 이 기능을 더 이상 사용하지 않고 있습니다. 아래는 간단한 예지이지만 더 자세한 내용과 예는 이 웹사이트에서 참조하시는 것을 추천드립니다.

plot1 <- DimPlot(pbmc3k.final)
plot2 <- FeatureScatter(pbmc3k.final, feature1 = "LYZ", feature2 = "CCL5")
# Combine two plots
plot1 + plot2
https://satijalab.org/seurat/articles/visualization_vignette_files/figure-html/combining_plots-1.png
# Remove the legend from all plots
(plot1 + plot2) & NoLegend()
https://satijalab.org/seurat/articles/visualization_vignette_files/figure-html/combining_plots-2.png

Leave a Reply

Your email address will not be published. Required fields are marked *