Xenium

preamble

library(sf)
library(dplyr)
library(ggplot2)
library(patchwork)
library(SpatialData)
library(SpatialData.data)
library(SpatialData.plot)
library(SingleCellExperiment)
(sd <- JanesickBreastXeniumRep1())
class: SpatialData
- images(2):
  - morphology_focus (1,25778,35416)
  - morphology_mip (1,25778,35416)
- labels(0):
- points(1):
  - transcripts (42638083)
- shapes(2):
  - cell_boundaries (167780,circle)
  - cell_circles (167780,circle)
- tables(1):
  - table (313,167780) [cell_circles]
coordinate systems(2):
- global(5): morphology_focus morphology_mip cell_boundaries
  cell_circles transcripts
- aligned(5): morphology_focus morphology_mip cell_boundaries
  cell_circles transcripts

analysis

sp <- crop(sd, list(xmin=17e3, xmax=20e3, ymin=13e3, ymax=14e3))
point(sp) <- mutate(point(sp) , nuc=as.logical(overlaps_nucleus))
plotSpatialData() + 
    plotImage(sp) +
    plotPoint(sp, size=0.2, n=2e4, col="nuc") +
    scale_color_manual(values=c("blue", "deeppink")) +
    guides(col=guide_legend(override.aes=list(size=2))) +
    plotShape(sp, col="cyan", fill=NA)

# make table annotate boundaries
regions(tables(sd)[[1]]) <- "cell_boundaries"
# bounding box crop
bb <- list(xmin=4e3, xmax=12e3, ymin=8e3, ymax=12e3)
(sp <- crop(sd, bb))
class: SpatialData
- images(2):
  - morphology_focus (1,4000,8000)
  - morphology_mip (1,4000,8000)
- labels(0):
- points(1):
  - transcripts (2147181)
- shapes(2):
  - cell_boundaries (8163,circle)
  - cell_circles (7942,circle)
- tables(1):
  - table (313,8163) [cell_boundaries]
coordinate systems(2):
- global(5): morphology_focus morphology_mip cell_boundaries
  cell_circles transcripts
- aligned(5): morphology_focus morphology_mip cell_boundaries
  cell_circles transcripts
plotSpatialData() + 
    plotShape(sp, col=NA, fill="transcript_counts") +
    plotPoint(sp, size=0.2, n=2e4, key="EPCAM", col="red") +
    scale_fill_gradientn(colors=hcl.colors(9, "Roma"), trans="log10")

ks <- c("CAFs", "Endothelial")
(sp <- query(sd, celltype_major %in% ks))
class: SpatialData
- images(0):
- labels(0):
- points(0):
- shapes(1):
  - cell_boundaries (36148,circle)
- tables(1):
  - table (313,36148) [cell_boundaries]
coordinate systems(2):
- global(1): cell_boundaries
- aligned(1): cell_boundaries
plotSpatialData() +
    plotShape(sp, size=0.2, colour="celltype_major") +
    guides(col=guide_legend(override.aes=list(size=2)))

appendix

sessionInfo()
R version 4.6.0 (2026-04-24)
Platform: aarch64-apple-darwin23
Running under: macOS Sequoia 15.6.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] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

time zone: Europe/Madrid
tzcode source: internal

attached base packages:
[1] stats4    stats     graphics  grDevices utils     datasets  methods  
[8] base     

other attached packages:
 [1] SingleCellExperiment_1.35.0 SummarizedExperiment_1.43.0
 [3] Biobase_2.73.1              GenomicRanges_1.65.0       
 [5] Seqinfo_1.3.0               IRanges_2.47.0             
 [7] S4Vectors_0.51.1            BiocGenerics_0.59.0        
 [9] generics_0.1.4              MatrixGenerics_1.25.0      
[11] matrixStats_1.5.0           SpatialData.plot_0.99.6    
[13] SpatialData.data_0.99.6     SpatialData_0.99.35        
[15] patchwork_1.3.2             ggplot2_4.0.3              
[17] dplyr_1.2.1                 sf_1.1-1                   

loaded via a namespace (and not attached):
 [1] DBI_1.3.0           bitops_1.0-9        RBGL_1.89.0        
 [4] httr2_1.2.2         anndataR_1.3.0      rlang_1.2.0        
 [7] magrittr_2.0.5      Rarr_2.1.7          otel_0.2.0         
[10] e1071_1.7-17        compiler_4.6.0      RSQLite_2.4.6      
[13] dir.expiry_1.21.0   paws.storage_0.9.0  png_0.1-9          
[16] fftwtools_0.9-11    vctrs_0.7.3         pkgconfig_2.0.3    
[19] wk_0.9.5            crayon_1.5.3        fastmap_1.2.0      
[22] dbplyr_2.5.2        XVector_0.53.0      paws.common_0.8.9  
[25] rmarkdown_2.31      graph_1.91.0        purrr_1.2.2        
[28] bit_4.6.0           xfun_0.57           cachem_1.1.0       
[31] grumpy_0.1.0        jsonlite_2.0.0      blob_1.3.0         
[34] DelayedArray_0.39.1 uuid_1.2-2          tweenr_2.0.3       
[37] jpeg_0.1-11         tiff_0.1-12         parallel_4.6.0     
[40] R6_2.6.1            RColorBrewer_1.1-3  reticulate_1.46.0  
[43] assertthat_0.2.1    Rcpp_1.1.1-1.1      knitr_1.51         
[46] R.utils_2.13.0      Matrix_1.7-5        tidyselect_1.2.1   
[49] duckspatial_1.0.0   rstudioapi_0.18.0   dichromat_2.0-0.1  
[52] abind_1.4-8         EBImage_4.55.0      curl_7.1.0         
[55] lattice_0.22-9      tibble_3.3.1        withr_3.0.2        
[58] S7_0.2.2            evaluate_1.0.5      units_1.0-1        
[61] proxy_0.4-29        polyclip_1.10-7     BiocFileCache_3.3.0
[64] pillar_1.11.1       filelock_1.0.3      KernSmooth_2.23-26 
[67] RCurl_1.98-1.18     nanoarrow_0.8.0     scales_1.4.0       
[70] class_7.3-23        glue_1.8.1          tools_4.6.0        
[73] ggnewscale_0.5.2    locfit_1.5-9.12     grid_4.6.0         
[76] duckdb_1.5.2        basilisk_1.25.0     ggforce_0.5.0      
[79] cli_3.6.6           rappdirs_0.3.4      S4Arrays_1.13.0    
[82] arrow_24.0.0        geoarrow_0.4.2      gtable_0.3.6       
[85] R.methodsS3_1.8.2   digest_0.6.39       classInt_0.4-11    
[88] SparseArray_1.13.2  ZarrArray_1.1.0     htmlwidgets_1.6.4  
[91] farver_2.1.2        memoise_2.0.1       htmltools_0.5.9    
[94] R.oo_1.27.1         lifecycle_1.0.5     bit64_4.8.0        
[97] MASS_7.3-65