# Beyond Sequence-based Spatially-Resolved Data

Starting from Version 1.2.0, `escheR` package supports additional two data structures as input, including `SpatialExperiment` and `data.frame` from `base` R. In addition, `escheR` supports in-situ visualization of image-based spatially resolved data, which will be the focus of future development.

# Visualized Dimensionality Reduced Embedding with `SingleCellExperiment`

## `SpatialExperiment` inherits `SingleCellExperiment`

Following the same syntax, one can also visualize dimensionality reduced embeddings of a `SpatialExperiment` object by providing the argument `dimred` with a non-null value. Hence, the first 2 columns of the corresponding `reducedDim(spe)` assay will be used as the x-y coordinate of the plot, replacing `spatialCoords(spe)`.

    library(escheR)
    library(STexampleData)
    library(scater)
    library(scran)

    spe <- Visium_humanDLPFC() |>
      logNormCounts()
    #> Warning in .library_size_factors(assay(x, assay.type), ...): 'librarySizeFactors' is deprecated.
    #> Use 'scrapper::centerSizeFactors' instead.
    #> See help("Deprecated")
    #> Warning in .local(x, ...): 'normalizeCounts' is deprecated.
    #> Use 'scrapper::normalizeCounts' instead.
    #> See help("Deprecated")
    spe <- spe[, spe$in_tissue == 1]
    spe <- spe[, !is.na(spe$ground_truth)]
    top.gene <- getTopHVGs(spe, n=500)
    #> Warning in getTopHVGs(spe, n = 500): 'getTopHVGs' is deprecated.
    #> Use 'scrapper::chooseHighlyVariableGenes' instead.
    #> See help("Deprecated")
    #> Warning in fitTrendVar(fm, fv, ...): 'fitTrendVar' is deprecated.
    #> Use 'scrapper::fitVarianceTrend' instead.
    #> See help("Deprecated")
    #> Warning in combineBlocks(collected, method = method, equiweight = equiweight, : 'combineBlocks' is deprecated.
    #> See help("Deprecated")

    set.seed(100) # See below.
    spe <- runPCA(spe, subset_row = top.gene)

    make_escheR(
      spe,
      dimred = "PCA"
    ) |>
      add_fill(var = "ground_truth") +
      theme_minimal()

# Hex Binning

    spe$counts_MOBP <- counts(spe)[which(rowData(spe)$gene_name=="MOBP"),]
    spe$ground_truth <- factor(spe$ground_truth)

    # Point Binning version
    make_escheR(
      spe,
      dimred = "PCA"
    ) |>
      add_ground_bin(
        var = "ground_truth"
        ) |>
      add_fill_bin(
        var = "counts_MOBP"
        ) +
      # Customize aesthetics
       scale_fill_gradient(low = "white", high = "black", name = "MOBP Count")+
      scale_color_discrete(name = "Spatial Domains") +
      theme_minimal()

> Note 1: The strategy of binning to avoid overplotting is previously proposed in `schex`. While we provide an implementation in `escheR`, we would caution our users that the binning strategy could lead to intermixing of cluster memberships. In our implementation, the majority membership of the data points belonging to a bin is selected as the label of the bin. Users should use the binning strategy under their own discretion, and interpret the visualization carefully.

> Note 2: `add_fill_bin()` shoudl be applied after `add_ground_bin()` for the better visualization outcome.

# Image-based `SpatialExperiment` Object

To demonstrate the principle that `escheR` can be used to visualize image-based spatially-resolved data pending optimization, we include two image-based spatially resolved transcriptomics data generated via seqFish platform and Slide-seq V2 platform respectively. The two datasets have been previously curated in the `STexampleData` package

## seqFISH

    library(STexampleData)
    library(escheR)
    spe_seqFISH <- seqFISH_mouseEmbryo()

    make_escheR(spe_seqFISH) |>
      add_fill(var = "embryo")

> NOTE: trimming down the `colData(spe)` before piping into make-escheR could reduce the computation time to make the plots, specifically when `colData(spe)` contains extremely large number of irrelavent features/columns.

## SlideSeqV2

    library(STexampleData)
    library(escheR)
    spe_slideseq <- SlideSeqV2_mouseHPC()

    make_escheR(spe_slideseq) |>
      add_fill(var = "celltype")

# Beyond Bioconductor Eco-system

We aim to provide accessibility to all users regardless of their programming background and preferred single-cell analysis pipelines. Nevertheless , with limited resource, our sustaining efforts will prioritize towards the maintenance of the established functionality and the optimization for image-based spatially resolved data. We regret we are not be able to provide seamless interface to other R pipelines such as `Seurat` and `Giotto` in foreseeable future.

Instead, we provide a generic function that works with a `data.frame` object as input. For example, relevant features in `Suerat` can be easily exported as a `data.frame` object manually or via `tidyseurat`[https://github.com/stemangiola/tidyseurat]. The exported data frame can be pipe into `escheR`.

    library(escheR)
    library(Seurat)
    pbmc_small <- SeuratObject::pbmc_small
    pbmc_2pc <- pbmc_small@reductions$pca@cell.embeddings[,1:2]
    pbmc_meta <- pbmc_small@meta.data

    #> Call generic function for make_escheR.data.frame
    make_escheR(
      object = pbmc_meta,
      .x = pbmc_2pc[,1],
      .y = pbmc_2pc[,2]) |>
      add_fill(var = "groups")

# Session information

    utils::sessionInfo()
    #> R version 4.6.0 Patched (2026-04-24 r89963)
    #> Platform: aarch64-apple-darwin23
    #> Running under: macOS Tahoe 26.3.1
    #>
    #> Matrix products: default
    #> BLAS:   /Library/Frameworks/R.framework/Versions/4.6/Resources/lib/libRblas.0.dylib
    #> LAPACK: /Library/Frameworks/R.framework/Versions/4.6/Resources/lib/libRlapack.dylib;  LAPACK version 3.12.1
    #>
    #> locale:
    #> [1] C/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
    #>
    #> time zone: America/New_York
    #> tzcode source: internal
    #>
    #> attached base packages:
    #> [1] stats4    stats     graphics  grDevices utils     datasets  methods
    #> [8] base
    #>
    #> other attached packages:
    #>  [1] scran_1.40.0                scater_1.40.0
    #>  [3] scuttle_1.22.0              ggpubr_0.6.3
    #>  [5] STexampleData_1.19.0        SpatialExperiment_1.22.0
    #>  [7] SingleCellExperiment_1.34.0 SummarizedExperiment_1.42.0
    #>  [9] Biobase_2.72.0              GenomicRanges_1.64.0
    #> [11] Seqinfo_1.2.0               IRanges_2.46.0
    #> [13] S4Vectors_0.50.0            MatrixGenerics_1.24.0
    #> [15] matrixStats_1.5.0           ExperimentHub_3.2.0
    #> [17] AnnotationHub_4.2.0         BiocFileCache_3.2.0
    #> [19] dbplyr_2.5.2                BiocGenerics_0.58.0
    #> [21] generics_0.1.4              escheR_1.12.0
    #> [23] ggplot2_4.0.3               BiocStyle_2.40.0
    #>
    #> loaded via a namespace (and not attached):
    #>   [1] DBI_1.3.0            gridExtra_2.3        httr2_1.2.2
    #>   [4] rlang_1.2.0          magrittr_2.0.5       otel_0.2.0
    #>   [7] compiler_4.6.0       RSQLite_2.4.6        png_0.1-9
    #>  [10] vctrs_0.7.3          pkgconfig_2.0.3      crayon_1.5.3
    #>  [13] fastmap_1.2.0        backports_1.5.1      magick_2.9.1
    #>  [16] XVector_0.52.0       labeling_0.4.3       rmarkdown_2.31
    #>  [19] ggbeeswarm_0.7.3     tinytex_0.59         purrr_1.2.2
    #>  [22] bit_4.6.0            bluster_1.22.0       xfun_0.57
    #>  [25] beachmat_2.28.0      cachem_1.1.0         jsonlite_2.0.0
    #>  [28] blob_1.3.0           DelayedArray_0.38.0  BiocParallel_1.46.0
    #>  [31] cluster_2.1.8.2      irlba_2.3.7          parallel_4.6.0
    #>  [34] broom_1.0.12         R6_2.6.1             bslib_0.10.0
    #>  [37] RColorBrewer_1.1-3   limma_3.68.0         car_3.1-5
    #>  [40] jquerylib_0.1.4      Rcpp_1.1.1-1.1       bookdown_0.46
    #>  [43] knitr_1.51           igraph_2.3.0         Matrix_1.7-5
    #>  [46] tidyselect_1.2.1     viridis_0.6.5        dichromat_2.0-0.1
    #>  [49] abind_1.4-8          yaml_2.3.12          codetools_0.2-20
    #>  [52] curl_7.1.0           lattice_0.22-9       tibble_3.3.1
    #>  [55] BumpyMatrix_1.20.0   withr_3.0.2          KEGGREST_1.52.0
    #>  [58] S7_0.2.2             evaluate_1.0.5       Biostrings_2.80.0
    #>  [61] pillar_1.11.1        BiocManager_1.30.27  filelock_1.0.3
    #>  [64] carData_3.0-6        BiocVersion_3.23.1   scales_1.4.0
    #>  [67] glue_1.8.1           metapod_1.20.0       tools_4.6.0
    #>  [70] hexbin_1.28.5        BiocNeighbors_2.6.0  ScaledMatrix_1.20.0
    #>  [73] locfit_1.5-9.12      ggsignif_0.6.4       cowplot_1.2.0
    #>  [76] grid_4.6.0           tidyr_1.3.2          edgeR_4.10.0
    #>  [79] AnnotationDbi_1.74.0 beeswarm_0.4.0       BiocSingular_1.28.0
    #>  [82] vipor_0.4.7          rsvd_1.0.5           Formula_1.2-5
    #>  [85] cli_3.6.6            rappdirs_0.3.4       S4Arrays_1.12.0
    #>  [88] viridisLite_0.4.3    dplyr_1.2.1          gtable_0.3.6
    #>  [91] rstatix_0.7.3        sass_0.4.10          digest_0.6.39
    #>  [94] dqrng_0.4.1          ggrepel_0.9.8        SparseArray_1.12.0
    #>  [97] rjson_0.2.23         farver_2.1.2         memoise_2.0.1
    #> [100] htmltools_0.5.9      lifecycle_1.0.5      httr_1.4.8
    #> [103] statmod_1.5.1        bit64_4.8.0