Skip to contents

Plot transcript spot density as 2D histogram

Usage

plotTxBin2D(
  sfe = NULL,
  data_dir = NULL,
  tech = c("Vizgen", "Xenium", "CosMX"),
  file = NULL,
  sample_id = "all",
  bins = 200,
  binwidth = NULL,
  hex = FALSE,
  ncol = NULL,
  bbox = NULL,
  gene = "all",
  spatialCoordsNames = c("X", "Y"),
  gene_col = "gene",
  rowGeometryName = "txSpots",
  flip = FALSE,
  tx_file = NULL
)

Arguments

sfe

A SpatialFeatureExperiment object.

data_dir

Top level directory of the output files. This can be specified in place of sfe to directly read the transcript spot coordinates from the file. When reading from file, transcripts from this file are plotted and argument sample_id is ignored.

tech

Name of the commercial technology, must be one of Vizgen, Xenium, and CosMX.

file

File (not GeoParquet) with numeric columns for xy coordinates of the transcript spots. Ignored if data_dir is specified.

sample_id

Sample(s) in the SFE object whose cells/spots to use. Can be "all" to compute metric for all samples; the metric is computed separately for each sample.

bins

Number of bins. Can be a vector of length 2 to specify for x and y axes separately.

binwidth

Width of bins, passed to geom_bin2d or geom_hex.

hex

Logical, whether to use hexagonal bins.

ncol

Number of columns if plotting multiple features. Defaults to NULL, which means using the same logic as facet_wrap, which is used by patchwork's wrap_plots by default.

bbox

A bounding box to specify a smaller region to plot, useful when the dataset is large. Can be a named numeric vector with names "xmin", "xmax", "ymin", and "ymax", in any order. If plotting multiple samples, it should be a matrix with sample IDs as column names and "xmin", "ymin", "xmax", and "ymax" as row names. If multiple samples are plotted but bbox is a vector rather than a matrix, then the same bounding box will be used for all samples. You may see points at the edge of the geometries if the intersection between the bounding box and a geometry happens to be a point there. If NULL, then the entire tissue is plotted.

gene

Character vector of names of genes to plot. If "all" then transcript spots of all genes are plotted.

spatialCoordsNames

Column names for the x, y, and optionally z coordinates of the spots. The defaults are for Vizgen.

gene_col

Column name for genes.

rowGeometryName

Name of a rowGeometry of the SFE object to plot.

flip

Logical, whether to flip the y axis when plotting data from file.

tx_file

File path to GeoParquet file of the transcript spots if you don't wish to load all transcript spots into the SFE object. See formatTxSpots on generating such a GeoParquet file.

Value

A ggplot object, facetting by sample.