Skip to content

Simple functions to create ggplot2 plots to visualize single cell expression data in 2D dimensionality reductions to avoid overplotting. Includes a wrapper for Seurat objects.

License

derpylz/hexpression

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Hex Plots for Single Cell Expression Data

Simple functions to create ggplot2 plots to visualize single cell expression data in 2D dimensionality reductions to avoid overplotting. Inspired by the ggHex function in ArchR. Includes a wrapper for Seurat objects that is almost a drop-in replacement for FeaturePlot. Mainly created for convenience and personal use, but feel free to use it if you find it useful.

Motivation

When plotting gene expression in a 2D plot, overplotting can be a problem, especially for data sets with many cells. The default Seurat FeaturePlot has the option of ordering the cells by expression, but this can lead to overestimating the number of cells with high expression, when order = TRUE or underestimating when order = FALSE. The ggHex function in ArchR is a nice alternative, as it plots hexagonal bins which are colored by the median, mean or another summarizing function expression of the cells in their area. However, ggHex is not a drop-in replacement for FeaturePlot and loading ArchR for this one function is a bit overkill. This package provides a simple function to create hex plots based on ggplot2 for single cell expression data, which can be used as a drop-in replacement for FeaturePlot.

In the figure below you can see a comparison of the default FeaturePlot and the hex plot for the same data. From left to right: FeaturePlot with order = TRUE, FeaturePlot with order = FALSE, hex plot.

FeaturePlot and HexPlot side by side

Installation

# install.packages("remotes")
remotes::install_github("derpylz/hexpression")

Usage

library(hexpression)
library(Seurat)
# Load example data
library(SeuratData)
InstallData("bmcite")
bm <- LoadData("bmcite")
# Run dimensionality reduction
bm <- RunUMAP(bm, nn.name = "weighted.nn", reduction.name = "wnn.umap", reduction.key = "wnnUMAP_", return.model = TRUE)
# Plot expression of TRDC
HexPlot(bm, "TRDC", reduction = "wnn.umap")
# Plot expression split by cell type
HexPlot(bm, "TRDC", reduction = "wnn.umap", split.by = "celltype.l1")
# Plot multiple genes
HexPlot(bm, c("TRDC", "AVP"), reduction = "wnn.umap")
# Plot multiple genes split by cell type
HexPlot(bm, c("TRDC", "AVP"), reduction = "wnn.umap", split.by = "celltype.l1")

License

Apache License 2.0

Similar packages

About

Simple functions to create ggplot2 plots to visualize single cell expression data in 2D dimensionality reductions to avoid overplotting. Includes a wrapper for Seurat objects.

Topics

Resources

License

Stars

Watchers

Forks

Languages