Contents

1 Introduction

The ggspavis package contains a set of visualization functions for spatial transcriptomics data, designed to work with the SpatialExperiment Bioconductor object class.

2 Examples

Load some example datasets from the STexampleData or spatialLIBD package and create some example plots to demonstrate ggspavis.

library(ggspavis)
library(STexampleData)
library(patchwork)
library(scater)
library(scran)
library(OSTA.data)
library(VisiumIO)
library(SpatialExperiment)

2.1 Sequencing-based spatial transcriptomics data

2.1.1 Spot shape - Slide-seq and Visium

First, we start with a demo for Slide-seq V2 mouse brain dataset.

spe_slide <- STexampleData::SlideSeqV2_mouseHPC()
spe_slide$loglibsize <- log1p(colSums(counts(spe_slide)))

We can visualize the barcoded beads of Slide-seq V2 spatially with plotCoords().

(plotCoords(spe_slide, annotate = "celltype", 
            in_tissue = NULL, point_size = 0.1) + 
  guides(color=guide_legend(override.aes = list(size = 3), ncol = 2)) |
  plotCoords(spe_slide, annotate = "loglibsize", 
             in_tissue = NULL, point_size = 0.1) + 
  scale_color_gradient(name = "Log library size") + ggtitle("")) +
  plot_annotation(title = 'Slide-seq V2 Mouse Brain')

Similarly, in a 10x Genomics Visium mouse brain dataset, we generate visualizations of library size and expression levels of selected genes. Both plotVisium() and plotCoords() reflect the spatial coordinates of spots, with the former also overlaying spots on the H&E histology image. Note that plotVisium() accepts a SpatialExperiment class object (with image data), while other functions in the package accept either SpatialExperiment or SingleCellExperiment class objects.

# load data in SpatialExperiment format
spe_vm <- Visium_mouseCoronal()
rownames(spe_vm) <- rowData(spe_vm)$gene_name
colData(spe_vm)$sum <- colSums(counts(spe_vm))

With plotVisium() annotated by a continuous variable, you can adjust palette, legend position, scaling of the variable, and whether to highlight spots that are in tissue, etc.

p1 <- plotVisium(spe_vm, annotate = "sum", highlight = "in_tissue", 
                 legend_position = "none")
p2 <- plotVisium(spe_vm, annotate = "sum", highlight = "in_tissue", 
                 pal = "darkred") + 
  guides(fill = guide_colorbar(title = "Libsize"))

# display panels using patchwork
p1 | p2

plotVisium() can also be used to visualize gene expression.

p1 <- plotVisium(spe_vm, annotate = "Gapdh", highlight = "in_tissue")
p2 <- plotVisium(spe_vm, annotate = "Mbp", highlight = "in_tissue")

# display panels using patchwork
p1 | p2

Two other possibilities with plotVisium() are to show only spots or only the H&E image.

p1 <- plotVisium(spe_vm, annotate = "Mbp", 
                 highlight = "in_tissue", image = FALSE)
p2 <- plotVisium(spe_vm, annotate = "Mbp", 
                 highlight = "in_tissue", spots = FALSE)

# display panels using patchwork
p1 | p2