FeatureOverlay: Overlay features on HE images

FeatureOverlayR Documentation

Overlay features on HE images

Description

Graphs the selected features on a 2D grid of spots overlaid on top of an HE images. If numerical features are selected, e.g. gene expression values, a "spatial heatmap" will be drawn and if a categorical variable is selected (such as cluster labels) each group of spots will be assigned a color. Categorical and numerical values cannot be combined.

Usage

FeatureOverlay(
  object,
  features,
  sampleids = 1,
  spots = NULL,
  ncols = NULL,
  layout.by.feature = TRUE,
  type = NULL,
  min.cutoff = NA,
  max.cutoff = NA,
  slot = "data",
  blend = FALSE,
  pt.size = 2,
  pt.alpha = 1,
  pt.border = TRUE,
  add.alpha = FALSE,
  palette = NULL,
  cols = NULL,
  spot.colors = NULL,
  center.zero = FALSE,
  channels.use = NULL,
  dark.theme = FALSE,
  show.sb = TRUE,
  value.scale = c("samplewise", "all"),
  label.by = NULL,
  verbose = FALSE,
  ...
)

Arguments

object

Seurat object

features
  • An Assay feature (e.g. a gene name - "MS4A1")

  • A column name from meta.data (e.g. mitochondrial percentage - "percent.mito")

sampleids

Names of samples to plot

spots

Character vector with spot IDs to plot [default: all spots]

ncols

Number of columns in the subplot layout grid. (see Arrange plots for a detailed description)

layout.by.feature

Flip the arrangement of the subplot layout grid.

type

Image type to plot on. Here you can specify any of the images available in your Seurat object. To get this list you can run the rasterlists function on your Seurat object. If the type is not specified, the images will be prioritized in the following order if they are available; "processed", "masked" and "raw".

min.cutoff

Vector of minimum and maximum cutoff values for each feature, may specify quantile in the form of 'q##' where '##' is the quantile (eg, 'q1', 'q10'). This can be useful if you have outlier values that skew the colorscale in the plot. For example, if you specify 'q1', you will trim of values below the 1st percentile. [default: no cuttoffs]

max.cutoff

Vector of minimum and maximum cutoff values for each feature, may specify quantile in the form of 'q##' where '##' is the quantile (eg, 'q1', 'q10'). This can be useful if you have outlier values that skew the colorscale in the plot. For example, if you specify 'q1', you will trim of values below the 1st percentile. [default: no cuttoffs]

slot

Which slot to pull expression data from? [dafault: 'data']

blend

Scale and blend expression values to visualize coexpression of two features (this options will override other coloring parameters). See 'Blending values' below for a more thourough description.

pt.size

Point size of each ST spot [default: 1]

pt.alpha

Opacity of each ST spot [default: 1]

pt.border

Should a border be drawn around the spots? [default: TRUE]

add.alpha

Scale spot opacity by selected feature. Higher values get more opaque while lower values make spots transparent.

palette

Color palette used for spatial heatmap (see palette.select(info = T) for available options). Disabled if a color vector is provided (see cols below).

cols

A vector of colors to use for colorscale, e.g. cols = c("blue", "white", "red") will create a gradient color scale going from blue to white to red. This options will deactivate the palette option.

spot.colors

A data.frame with custom colors for each spot. The data.frame must have rownames which are matched with the spot ids and matching dimensions. Note that the data.rame must also match the 'sampleids' provided, e.g. if you set 'sampleids' to 1 the spot.colors data.frame must match the spots that are present in sample 1. If the spot.colors data.frame contains more than 1 column, only the first column will be used.

center.zero

Specifies whther or not the colorscale should be centered around 0. For some values, such as Principal Component vectors, the distribution of values is centered at 0 and in that case it can be appropriate to use a divergent colorscale with a predefined value for 0. If this parameter is set to TRUE, the ggplot2 function scale_color_gradient2 will be used to control the coloring instead of scale_color_gradientn. If center.zero is set to FALSE, the colorscale will simply map the values in equally spaced intervals which could skew the interpretaion of the output plot.

channels.use

Color channels to use for blending. Has to be a character vector of length 2 or 3 with "red", "green" and "blue" color names specified [default: c("red", "green", "blue)]

dark.theme

Switches color of scalebar to 'white'

show.sb

Should the size bar be displayed? [default: TRUE]

value.scale

Defines how the feature values should be mapped to the colorbar. If 'value.scale = "samplewise"', each feature will be scaled independently and if 'value.scale = "all"' the features will all have the same value reange.

label.by

Feature to relabel facets by. By default, facets are given a unique section number ranging grom 1 to the number of sections available in the 'Staffli' object. If you want to relabel these facets you can pass the name of a column that keeps the labels that you want to use. For example, if you wish to rename the facets to use labels defined by a charcater vector in column "section_id" in your meta.data slot, you can pass 'label.by = "section_id"' to relabel the facets. Only works for categorical group variables with where the number of groups is less than or equal to the number of tissue sections in your Staffli object.

verbose

Print messages

...

Parameters passed to FeatureOverlay

Details

NOTE that this function draws sample 1 as default, but can take multiple samples as well using the 'sampleids argument'.

It is typically difficult to explore details in the HE image when diplaying multiple samples side by side, so we recommend to draw the plots for one sample at the time. If you have higher resolution images, it could also take significant time to draw the plots.

Blending values

The blend option can be useful if you wish to visualize multiple numerical features simultaneuosly and works for two or three feature value vectors. Each of the selected vectors are rescaled from 0 to 1 and are used as RGB color channels to produce mixed color for each spot. This can be particularly useful when looking at overlapping value vectors. For example, if you are looking at two overlapping value vectors "A" and "B" and use the blend option, the "A" values will be encoded in the "red" channel and the "B" values in the "green" channel. If a spot is purely "A" the color will be red and if it is purely "B" it will green. Any mixture of "A" and "B" will produce a color between red and green where a 50/50 mixture gives yellow color.

Arrange plots

The 'ncols' argument will determine the number of columns in the grid of subplots layout output by FeatureOverlay. By default, the subplots are arranged with features in columns and sections in rows where 'ncols = length(features)'. The 'layout.by.feature' can be used to flip the arrangement so that the sections are put in columns and dimensions along rows.

See Also

ST.FeaturePlot and ST.DimPlot for how to plot features without the HE image and DimOverlay for how to overlay dimensionality reduction output on the HE images.

Examples

## Not run: 
# Load images
se <- LoadImages(se)

# Overlay the number of unique genes and the number of
# UMIs per spot on the first two tissue sections
FeatureOverlay(se, features = c("nFeature_RNA", "nCount_RNA"), sampleids = 1:2)

# Plot selected genes on the first two tissue sections
FeatureOverlay(se, features = c("Cck", "Dcn"), sampleids = 1:2)

# Plot normalized values on the first two tissue sections
se <- SCTransform(se)
FeatureOverlay(se, features = c("Cck", "Dcn"), sampleids = 1:2)

# Change to scaled data
FeatureOverlay(se, features = c("Cck", "Dcn"), sampleids = 1:2,
               slot = "scale.data", center.zero = TRUE)

# Mask images and plot plot the slected genes on the masked images for samples 1 and 2
se <- MaskImages(se)
FeatureOverlay(se, features = c("Cck", "Dcn"), sampleids = 1:2, type = "masked")

## End(Not run)


jbergenstrahle/STUtility documentation built on March 14, 2023, 7:15 a.m.