1 Introduction

To keep the package size small, this vignette provides a quick-start example of co-visualizing bulk and single-cell assay data. For comprehensive instructions and examples, see the complete spatialHeatmap co-visualization vignette.

2 Getting Started

2.1 Installation

The spatialHeatmap package can be installed with the BiocManager::install command.

if (!requireNamespace("BiocManager", quietly = TRUE))
    install.packages("BiocManager")
BiocManager::install("spatialHeatmap")

2.2 Packages and Documentation

Next, the packages required for running the sample code in this vignette need to be loaded.

library(spatialHeatmap); library(SummarizedExperiment); library(ggplot2); library(SingleCellExperiment);
library(kableExtra); library(Seurat)

The following lists the vignette(s) of this package in an HTML browser. Clicking the name of the corresponding vignette will open it.

browseVignettes('spatialHeatmap')

To reduce runtime, intermediate results can be cached under ~/.cache/shm.

cache.pa <- '~/.cache/shm' # Set path of the cache directory

3 Quick Start

To obtain for examples with randomized data or parameters always the same results, a fixed seed is set.

set.seed(10)

This quick start example is demonstrated on ‘cell-by-group’ coloring by using a single-cell data set from oligodendrocytes of mouse brain (Marques et al. 2016), which is obtained from the scRNAseq (Risso and Cole 2022).

The single-cell data is first pre-processed by the process_cell_meta function that applies common QC, normalization and dimension reduction routines. The details of these pre-processing methods are described in the corresponding help file. Additional background information on these topics can be found in the OSCA tutorial.

sce.pa <- system.file("extdata/shinyApp/data", "cell_mouse_brain.rds", package="spatialHeatmap")
sce <- readRDS(sce.pa)
sce.dimred.quick <- process_cell_meta(sce)
colData(sce.dimred.quick)[1:3, 1:2]
## DataFrame with 3 rows and 2 columns
##                              label         age
##                        <character> <character>
## C1.1772096.085.B10          SN.VTA         p19
## C1.1772125.088.G02 corpus.callosum         p22
## C1.1772099.084.C06    zona.incerta         p19

The gene expression values in single-cell data are averaged within their group labels in the label column of colData slot, which correspond to their source tissues.

sce.aggr.quick <- aggr_rep(sce.dimred.quick, assay.na='logcounts', sam.factor='label', aggr='mean')

The aSVG of mouse brain is imported with the function read_svg and stored in an SVG object svg.mus.brain.

svg.mus.brain.pa <- system.file("extdata/shinyApp/data", "mus_musculus.brain.svg", package="spatialHeatmap")
svg.mus.brain <- read_svg(svg.mus.brain.pa)

A subset of features and related attributes are returned from svg.mus.brain, where fill and stroke refer to color and line width respectively.

tail(attribute(svg.mus.brain)[[1]])[, 1:4]
## # A tibble: 6 × 4
##   feature                      id             fill  stroke
##   <chr>                        <chr>          <chr>  <dbl>
## 1 brainstem                    UBERON_0002298 none    0.05
## 2 midbrain                     UBERON_0001891 none    0.05
## 3 dorsal.plus.ventral.thalamus UBERON_0001897 none    0.05
## 4 hypothalamus                 UBERON_0001898 none    0.05
## 5 nose                         UBERON_0000004 none    0.05
## 6 corpora.quadrigemina         UBERON_0002259 none    0.05

Due to differences in naming conventions, cell group labels and tissue labels are often programatically different. To match the two, a list with named components is used, where cell labels are in name slots and tissue features are corresponding list elements (translation map). This is a general approach for ensuring cell group labels and tissue labels are programmatically matched. Note, in the cell-to-tisssue mapping, each cell label can be matched to multiple aSVG features but not vice versa.

lis.match.quick <- list(hypothalamus=c('hypothalamus'), cortex.S1=c('cerebral.cortex', 'nose'))

For efficient data management and reusability, the data objects for co-visualization are stored in an SPHM container.

dat.quick <- SPHM(svg=svg.mus.brain, bulk=sce.aggr.quick, cell=sce.dimred.quick, match=lis.match.quick)

The co-visualization plot is created with gene Apod using the function covis. In the embedding plot, the hypothalamus and cortex.S1 cells are colored according to their respecitive aggregated expression values of Apod. In the SHM plot, aSVG features are assigned the same color as the matching cells defined in lis.match.quick. The cell.group argument refers to cell group labels in the colData slot of sce.aggr.quick, tar.cell specifies the target cell groups to show, and dimred specifies the embeddings.

shm.res.quick <- covis(data=dat.quick, ID=c('Apod'), dimred='UMAP', cell.group='label', tar.cell=names(lis.match.quick), assay.na='logcounts', bar.width=0.09, dim.lgd.nrow=2, legend.r=1.5, legend.key.size=0.02, legend.text.size=10, legend.nrow=4, h=0.6, verbose=FALSE) 
Co-visualization of 'cell-by-group' coloring. The co-visualization is created with gene `Apod`. Single cells in the embedding plot and their matching aSVG features in the SHM are assigned the same colors that are created according to mean expression values of `Apod` within cell groups.

Figure 1: Co-visualization of ‘cell-by-group’ coloring
The co-visualization is created with gene Apod. Single cells in the embedding plot and their matching aSVG features in the SHM are assigned the same colors that are created according to mean expression values of Apod within cell groups.


4 Version Informaion

sessionInfo()
## R version 4.6.1 (2026-06-24)
## Platform: x86_64-pc-linux-gnu
## Running under: Ubuntu 24.04.5 LTS
## 
## Matrix products: default
## BLAS:   /home/biocbuild/bbs-3.24-bioc/R/lib/libRblas.so 
## LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.12.0  LAPACK version 3.12.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] Seurat_6.0.1                SeuratObject_5.4.0         
##  [3] sp_2.2-4                    kableExtra_1.4.1           
##  [5] SingleCellExperiment_1.36.0 ggplot2_4.0.4              
##  [7] SummarizedExperiment_1.44.0 Biobase_2.74.0             
##  [9] GenomicRanges_1.66.0        Seqinfo_1.4.0              
## [11] IRanges_2.48.0              S4Vectors_0.52.0           
## [13] BiocGenerics_0.60.0         generics_0.1.4             
## [15] MatrixGenerics_1.26.0       matrixStats_1.5.0          
## [17] spatialHeatmap_2.20.1       knitr_1.52                 
## [19] BiocStyle_2.42.0           
## 
## loaded via a namespace (and not attached):
##   [1] RColorBrewer_1.1-3   rstudioapi_0.19.0    jsonlite_2.0.0      
##   [4] magrittr_2.0.5       magick_2.9.1         farver_2.1.2        
##   [7] rmarkdown_2.32       fs_2.1.0             vctrs_0.7.3         
##  [10] memoise_2.0.1        base64enc_0.1-6      tinytex_0.62        
##  [13] htmltools_0.5.9      S4Arrays_1.14.0      BiocBaseUtils_1.16.0
##  [16] BiocNeighbors_2.8.0  SparseArray_1.14.0   gridGraphics_0.5-1  
##  [19] sctransform_0.4.3    sass_0.5.0           parallelly_1.50.0   
##  [22] KernSmooth_2.23-27   bslib_0.12.0         ica_1.0-3           
##  [25] plyr_1.8.9           cachem_1.1.0         igraph_2.3.4        
##  [28] mime_0.13            lifecycle_1.0.5      pkgconfig_2.0.3     
##  [31] Matrix_1.7-6         R6_2.6.1             fastmap_1.2.0       
##  [34] future_1.82.0        shiny_1.15.0         digest_0.6.39       
##  [37] rsvg_2.7.0           patchwork_1.3.2      AnnotationDbi_1.76.1
##  [40] irlba_2.4.1          RSpectra_0.16-2      shinytoastr_2.2.0   
##  [43] textshaping_1.1.0    RSQLite_3.54.1       beachmat_2.30.0     
##  [46] labeling_0.4.3       progressr_1.1.0      httr_1.4.9          
##  [49] abind_1.4-8          compiler_4.6.1       bit64_4.8.6         
##  [52] withr_3.0.3          S7_1.0.0             DBI_1.4.0           
##  [55] fastDummies_1.7.6    shinyAce_0.4.4       MASS_7.3-66         
##  [58] DelayedArray_0.40.0  tools_4.6.1          otel_0.3.0          
##  [61] httpuv_1.6.17        future.apply_1.21.0  glue_1.8.1          
##  [64] promises_1.5.0       grid_4.6.1           Rtsne_0.17          
##  [67] cluster_2.1.8.3      reshape2_1.4.5       gtable_0.3.6        
##  [70] spsComps_0.3.4.0     data.table_1.18.6.1  utf8_1.2.6          
##  [73] xml2_1.6.0           XVector_0.54.0       RcppAnnoy_0.0.23    
##  [76] ggrepel_0.9.8        RANN_2.6.3           pillar_1.11.1       
##  [79] stringr_1.6.0        RcppHNSW_0.7.0       yulab.utils_0.2.7   
##  [82] spam_2.11-4          limma_4.0.0          genefilter_1.96.0   
##  [85] later_1.4.8          splines_4.6.1        dplyr_1.2.1         
##  [88] lattice_0.23-1       survival_3.8-13      bit_4.6.0           
##  [91] annotate_1.92.0      tidyselect_1.2.1     pbapply_1.7-5       
##  [94] Biostrings_2.82.0    gridExtra_2.3.1      scrapper_1.8.0      
##  [97] grImport2_0.3-3      bookdown_0.48        edgeR_5.0.0         
## [100] scattermore_1.2      svglite_2.2.2        xfun_0.63           
## [103] shinydashboard_0.7.3 pls_2.9-0            statmod_1.5.2       
## [106] stringi_1.8.9        yaml_2.3.12          evaluate_1.0.5      
## [109] codetools_0.2-20     tibble_3.3.1         BiocManager_1.30.27 
## [112] ggplotify_0.1.4      cli_3.6.6            uwot_0.2.5          
## [115] xtable_1.8-8         systemfonts_1.3.4    jquerylib_0.1.4     
## [118] dichromat_2.0-1      Rcpp_1.1.2           globals_0.20.0      
## [121] png_0.1-9            XML_3.99-0.25        parallel_4.6.1      
## [124] assertthat_0.2.1     blob_1.3.0           dotCall64_1.2       
## [127] jpeg_0.1-11          listenv_1.1.0        viridisLite_0.4.3   
## [130] ggridges_0.5.7       scales_1.4.0         crayon_1.5.3        
## [133] rlang_1.3.0          cowplot_1.2.0        KEGGREST_1.54.0

5 Funding

This project has been funded by NSF awards: PGRP-1546879, PGRP-1810468, PGRP-1936492.

References

Marques, Sueli, Amit Zeisel, Simone Codeluppi, David van Bruggen, Ana Mendanha Falcão, Lin Xiao, Huiliang Li, et al. 2016. “Oligodendrocyte Heterogeneity in the Mouse Juvenile and Adult Central Nervous System.” Science 352 (6291): 1326–29.
Risso, Davide, and Michael Cole. 2022. scRNAseq: Collection of Public Single-Cell RNA-Seq Datasets.