We’ll demonstrate visualization techniques in Seurat using our previously computed Seurat object from the 2,700 PBMC tutorial. You can download that here

library(Seurat)
library(ggplot2)
pbmc <- readRDS(file = "../data/pbmc3k_final.rds")
pbmc$groups <- sample(c("group1", "group2"), size = ncol(pbmc), replace = TRUE)
features <- c("LYZ", "CCL5", "IL32", "PTPRCAP", "FCGR3A", "PF4")
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

Five visualizations of marker feature expression

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

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

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

# 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(pbmc, features = features) + RotatedAxis()

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

New additions to FeaturePlot

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

# Adjust the contrast in the plot
FeaturePlot(pbmc, 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(pbmc, features = c("MS4A1", "PTPRCAP"), min.cutoff = "q10", max.cutoff = "q90")

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

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

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")

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

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

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

# 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()

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")

# Use community-created themes, overwriting the default Seurat-applied theme Install ggmin with
# devtools::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()

Interactive plotting features

Seurat utilizes R’s plotly graphing library to create interactive plots. This interactive plotting feature works with any ggplot2-based scatter plots (requires a geom_point layer). To use, simply make a ggplot2-based scatter plot (such as DimPlot or FeaturePlot) and pass the resulting plot to HoverLocator

# 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")
HoverLocator(plot = plot, information = FetchData(pbmc, vars = c("ident", "PC_1", "nFeature_RNA")))

Another interactive feature provided by Seurat is being able to manually select cells for further investigation. We have found this particularly useful for small clusters that do not always separate using unbiased clustering, but which look tantalizingly distinct. You can now select these cells by creating a ggplot2-based scatter plot (such as with DimPlot or FeaturePlot, and passing the returned plot to CellSelector. CellSelector will return a vector with the names of the points selected, so that you can then set them to a new identity class and perform differential expression.

For example, lets pretend that DCs had merged with monocytes in the clustering, but we wanted to see what was unique about them based on their position in the tSNE plot.

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

We can then use SetIdent to turn these cells into their own mini-cluster.

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)
p_val avg_logFC pct.1 pct.2 p_val_adj
FCER1A 0 2.5652380 0.800 0.017 0
SERPINF1 0 1.0908678 0.457 0.012 0
HLA-DQB2 0 0.6713806 0.429 0.010 0
CD1C 0 1.2327732 0.514 0.025 0
ENHO 0 0.9520174 0.400 0.010 0
ITM2C 0 1.0806170 0.371 0.010 0

Using CellSelector to Automatically Assign Cell Identities

In addition to returning a vector of cell names, CellSelector can also take the selected cells and assign a new identity to them, returning a Seurat object with the identity classes already set. This is done by passing the Seurat object used to make the plot into CellSelector, as well as an identity class. As an example, we’re going to select the same set of cells as before, and set their identity class to “selected”

pbmc <- CellSelector(plot = plot, object = pbmc, ident = "selected")

levels(pbmc)
## [1] "selected"     "Naive CD4 T"  "Memory CD4 T" "CD14+ Mono"  
## [5] "B"            "CD8 T"        "FCGR3A+ Mono" "NK"          
## [9] "Platelet"

Plotting Accessories

Along with new functions add interactive functionality to plots, Seurat provides new accessory functions for manipulating and combining plots.

# 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")

# 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)

# Plotting multiple plots at once is easy with CombinePlots
plot1 <- DimPlot(pbmc)
plot2 <- FeatureScatter(pbmc, feature1 = "LYZ", feature2 = "CCL5")
# CombinePlots takes a list of ggplot2-based plots
CombinePlots(plots = list(plot1, plot2))

# CombinePlots can also easily remove the legend from the plots by passing `legend = 'none'`;
# legends can also be combined with `legend = 'right'`
CombinePlots(plots = list(plot1, plot2), legend = "none")

# CombinePlots used cowplot:plot_grid under the hood, and will pass on additional arguments to
# cowplot::plot_grid