1 Introduction

Dot plots of single-cell RNA-seq data allow for an examination of the relationships between cell groupings (e.g. clusters) and marker gene expression. The scDotPlot package offers a unified approach to perform a hierarchical clustering analysis and add annotations to the columns and/or rows of a scRNA-seq dot plot. It works with SingleCellExperiment and Seurat objects as well as data frames. The scDotPlot() function uses data from scater::plotDots() or Seurat::DotPlot() along with the aplot package to add dendrograms from ggtree and optional annotations.

2 Installation

if (!requireNamespace("BiocManager", quietly = TRUE)) {
    install.packages("BiocManager")
}

BiocManager::install("scDotPlot")

To install the development version directly from GitHub:

if (!requireNamespace("remotes", quietly = TRUE)) {
    install.packages("remotes")
}

remotes::install_github("ben-laufer/scDotPlot")

3 SingleCellExperiment

3.1 Prepare object

First, we normalize the object and then, for the purpose of this example, subset to remove cells without cell-type labels.

library(scRNAseq)
library(scuttle)

sce <- ZeiselBrainData()

sce <- sce |> 
    logNormCounts() |>  
    subset(x = _, , level2class != "(none)")

3.2 Get features

The features argument accepts a character vector with the gene IDs. For this example, we quickly obtain the top markers of for each cell type and then add them to the rowData of the object.

library(scran)
library(purrr)
library(dplyr)
library(AnnotationDbi)

features <- sce |>
    scoreMarkers(sce$level1class) |>
    map(~ .x |>
            as.data.frame() |>
            arrange(desc(mean.AUC))|>
            dplyr::slice(1:6) |>
            rownames()) |> 
    unlist2()

rowData(sce)$Marker <- features[match(rownames(sce), features)] |>
    names()

3.3 Plot logcounts

Finally, we create the plot. The group arguments utilize the colData, while the features arguments use the rowData. The paletteList argument can be used to manually specify the colors for the annotations specified through groupAnno and featureAnno. The clustering of the columns shows that cell the cell sub-types cluster by cell-type, while the clustering of the rows shows that most of the markers clusters by their cell type.

library(scDotPlot)
library(ggsci)

sce |>
    scDotPlot(features = features,
              group = "level2class",
              groupAnno = "level1class",
              featureAnno = "Marker",
              groupLegends = FALSE,
              annoColors = list("level1class" = pal_d3()(7),
                                "Marker" = pal_d3()(7)),
              annoWidth = 0.02)

3.4 Plot Z-scores

Plotting by Z-score through scale = TRUE improves the clustering result for the rows.

sce |>
    scDotPlot(scale = TRUE,
              features = features,
              group = "level2class",
              groupAnno = "level1class",
              featureAnno = "Marker",
              groupLegends = FALSE,
              annoColors = list("level1class" = pal_d3()(7),
                                "Marker" = pal_d3()(7)),
              annoWidth = 0.02)

4 Seurat

4.1 Get features

After loading the example Seurat object, we find the top markers for each cluster and add them to the assay of interest.

library(Seurat)
library(SeuratObject)
library(tibble)

data("pbmc_small")

features <- pbmc_small |>
    FindAllMarkers(only.pos = TRUE, verbose = FALSE) |>
    group_by(cluster) |>
    dplyr::slice(1:6) |>
    dplyr::select(cluster, gene)

pbmc_small[[DefaultAssay(pbmc_small)]][[]] <- pbmc_small[[DefaultAssay(pbmc_small)]][[]] |>
    rownames_to_column("gene") |> 
    left_join(features, by = "gene") |> 
    column_to_rownames("gene")

features <- features |> 
    deframe()

4.2 Plot logcounts

Plotting a Seurat object is similair to plotting a SingleCellExperiment object.

pbmc_small |>
    scDotPlot(features = features,
              group = "RNA_snn_res.1",
              groupAnno = "RNA_snn_res.1",
              featureAnno = "cluster",
              annoColors = list("RNA_snn_res.1" = pal_d3()(7),
                                "cluster" = pal_d3()(7)),
              groupLegends = FALSE,
              annoWidth = 0.075)

4.3 Plot Z-scores

Again, we see that plotting by Z-score improves the clustering result for the rows.

pbmc_small |>
    scDotPlot(scale = TRUE,
              features = features,
              group = "RNA_snn_res.1",
              groupAnno = "RNA_snn_res.1",
              featureAnno = "cluster",
              annoColors = list("RNA_snn_res.1" = pal_d3()(7),
                                "cluster" = pal_d3()(7)),
              groupLegends = FALSE,
              annoWidth = 0.075)

5 Package support

The Bioconductor support site is the preferred method to ask for help. Before posting, it’s recommended to check previous posts for the answer and look over the posting guide. For the post, it’s important to use the scDotPlot tag and provide both a minimal reproducible example and session information.

6 Acknowledgement

This package was inspired by the single-cell example from aplot.

7 Session info

## R version 4.4.0 RC (2024-04-16 r86468)
## Platform: x86_64-pc-linux-gnu
## Running under: Ubuntu 22.04.4 LTS
## 
## Matrix products: default
## BLAS:   /home/biocbuild/bbs-3.20-bioc/R/lib/libRblas.so 
## LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.10.0
## 
## locale:
##  [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
##  [3] LC_TIME=en_GB              LC_COLLATE=C              
##  [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
##  [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
##  [9] LC_ADDRESS=C               LC_TELEPHONE=C            
## [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       
## 
## time zone: America/New_York
## tzcode source: system (glibc)
## 
## attached base packages:
## [1] stats4    stats     graphics  grDevices utils     datasets  methods  
## [8] base     
## 
## other attached packages:
##  [1] tibble_3.2.1                Seurat_5.1.0               
##  [3] SeuratObject_5.0.2          sp_2.1-4                   
##  [5] ggsci_3.2.0                 scDotPlot_0.99.2           
##  [7] AnnotationDbi_1.67.0        dplyr_1.1.4                
##  [9] purrr_1.0.2                 scran_1.33.0               
## [11] scuttle_1.15.0              scRNAseq_2.19.0            
## [13] SingleCellExperiment_1.27.2 SummarizedExperiment_1.35.0
## [15] Biobase_2.65.0              GenomicRanges_1.57.1       
## [17] GenomeInfoDb_1.41.1         IRanges_2.39.0             
## [19] S4Vectors_0.43.0            BiocGenerics_0.51.0        
## [21] MatrixGenerics_1.17.0       matrixStats_1.3.0          
## [23] BiocStyle_2.33.1           
## 
## loaded via a namespace (and not attached):
##   [1] fs_1.6.4                  ProtGenerics_1.37.0      
##   [3] spatstat.sparse_3.0-3     bitops_1.0-7             
##   [5] httr_1.4.7                RColorBrewer_1.1-3       
##   [7] tools_4.4.0               sctransform_0.4.1        
##   [9] alabaster.base_1.5.2      utf8_1.2.4               
##  [11] R6_2.5.1                  HDF5Array_1.33.2         
##  [13] uwot_0.2.2                lazyeval_0.2.2           
##  [15] rhdf5filters_1.17.0       withr_3.0.0              
##  [17] gridExtra_2.3             progressr_0.14.0         
##  [19] cli_3.6.2                 spatstat.explore_3.2-7   
##  [21] fastDummies_1.7.3         labeling_0.4.3           
##  [23] alabaster.se_1.5.2        sass_0.4.9               
##  [25] spatstat.data_3.0-4       ggridges_0.5.6           
##  [27] pbapply_1.7-2             yulab.utils_0.1.4        
##  [29] Rsamtools_2.21.0          scater_1.33.1            
##  [31] parallelly_1.37.1         limma_3.61.2             
##  [33] RSQLite_2.3.7             gridGraphics_0.5-1       
##  [35] generics_0.1.3            BiocIO_1.15.0            
##  [37] ica_1.0-3                 spatstat.random_3.2-3    
##  [39] Matrix_1.7-0              ggbeeswarm_0.7.2         
##  [41] fansi_1.0.6               abind_1.4-5              
##  [43] lifecycle_1.0.4           yaml_2.3.8               
##  [45] edgeR_4.3.4               rhdf5_2.49.0             
##  [47] SparseArray_1.5.8         BiocFileCache_2.13.0     
##  [49] Rtsne_0.17                grid_4.4.0               
##  [51] blob_1.2.4                promises_1.3.0           
##  [53] dqrng_0.4.1               ExperimentHub_2.13.0     
##  [55] crayon_1.5.2              miniUI_0.1.1.1           
##  [57] lattice_0.22-6            beachmat_2.21.3          
##  [59] cowplot_1.1.3             GenomicFeatures_1.57.0   
##  [61] KEGGREST_1.45.1           pillar_1.9.0             
##  [63] knitr_1.47                metapod_1.13.0           
##  [65] rjson_0.2.21              future.apply_1.11.2      
##  [67] codetools_0.2-20          leiden_0.4.3.1           
##  [69] glue_1.7.0                ggfun_0.1.5              
##  [71] data.table_1.15.4         treeio_1.29.0            
##  [73] vctrs_0.6.5               png_0.1-8                
##  [75] gypsum_1.1.4              spam_2.10-0              
##  [77] gtable_0.3.5              cachem_1.1.0             
##  [79] xfun_0.45                 S4Arrays_1.5.1           
##  [81] mime_0.12                 survival_3.7-0           
##  [83] statmod_1.5.0             bluster_1.15.0           
##  [85] fitdistrplus_1.1-11       ROCR_1.0-11              
##  [87] nlme_3.1-165              ggtree_3.13.0            
##  [89] bit64_4.0.5               alabaster.ranges_1.5.1   
##  [91] filelock_1.0.3            RcppAnnoy_0.0.22         
##  [93] bslib_0.7.0               irlba_2.3.5.1            
##  [95] vipor_0.4.7               KernSmooth_2.23-24       
##  [97] colorspace_2.1-0          DBI_1.2.3                
##  [99] tidyselect_1.2.1          bit_4.0.5                
## [101] compiler_4.4.0            curl_5.2.1               
## [103] httr2_1.0.1               BiocNeighbors_1.23.0     
## [105] DelayedArray_0.31.1       plotly_4.10.4            
## [107] bookdown_0.39             rtracklayer_1.65.0       
## [109] scales_1.3.0              lmtest_0.9-40            
## [111] rappdirs_0.3.3            goftest_1.2-3            
## [113] stringr_1.5.1             digest_0.6.35            
## [115] spatstat.utils_3.0-5      alabaster.matrix_1.5.3   
## [117] rmarkdown_2.27            XVector_0.45.0           
## [119] htmltools_0.5.8.1         pkgconfig_2.0.3          
## [121] sparseMatrixStats_1.17.2  highr_0.11               
## [123] dbplyr_2.5.0              fastmap_1.2.0            
## [125] ensembldb_2.29.0          rlang_1.1.4              
## [127] htmlwidgets_1.6.4         UCSC.utils_1.1.0         
## [129] shiny_1.8.1.1             DelayedMatrixStats_1.27.1
## [131] farver_2.1.2              jquerylib_0.1.4          
## [133] zoo_1.8-12                jsonlite_1.8.8           
## [135] BiocParallel_1.39.0       BiocSingular_1.21.1      
## [137] RCurl_1.98-1.14           magrittr_2.0.3           
## [139] ggplotify_0.1.2           GenomeInfoDbData_1.2.12  
## [141] dotCall64_1.1-1           patchwork_1.2.0          
## [143] Rhdf5lib_1.27.0           munsell_0.5.1            
## [145] Rcpp_1.0.12               viridis_0.6.5            
## [147] ape_5.8                   reticulate_1.37.0        
## [149] stringi_1.8.4             alabaster.schemas_1.5.0  
## [151] zlibbioc_1.51.1           MASS_7.3-61              
## [153] AnnotationHub_3.13.0      plyr_1.8.9               
## [155] parallel_4.4.0            listenv_0.9.1            
## [157] ggrepel_0.9.5             deldir_2.0-4             
## [159] Biostrings_2.73.1         splines_4.4.0            
## [161] tensor_1.5                locfit_1.5-9.9           
## [163] igraph_2.0.3              spatstat.geom_3.2-9      
## [165] RcppHNSW_0.6.0            reshape2_1.4.4           
## [167] ScaledMatrix_1.13.0       BiocVersion_3.20.0       
## [169] XML_3.99-0.16.1           evaluate_0.24.0          
## [171] BiocManager_1.30.23       httpuv_1.6.15            
## [173] RANN_2.6.1                tidyr_1.3.1              
## [175] polyclip_1.10-6           future_1.33.2            
## [177] scattermore_1.2           alabaster.sce_1.5.1      
## [179] ggplot2_3.5.1             rsvd_1.0.5               
## [181] xtable_1.8-4              restfulr_0.0.15          
## [183] AnnotationFilter_1.29.0   tidytree_0.4.6           
## [185] RSpectra_0.16-1           later_1.3.2              
## [187] viridisLite_0.4.2         aplot_0.2.3              
## [189] beeswarm_0.4.0            memoise_2.0.1            
## [191] GenomicAlignments_1.41.0  cluster_2.1.6            
## [193] globals_0.16.3