plot_meta: Meta function for plotting spatial heatmaps or co-visualizing...

View source: R/covis.R

plot_metaR Documentation

Meta function for plotting spatial heatmaps or co-visualizing bulk and single cell data

Description

This is a meta function for plotting spatial heatmaps or co-visualizing bulk and single cell data that takes as input file paths of assay data and aSVG files.

Usage

plot_meta(
  svg.path,
  bulk,
  cell = NULL,
  match.lis = NULL,
  assay.na = NULL,
  sam.factor = NULL,
  con.factor = NULL,
  aggr = "mean",
  ID,
  var.cell = NULL,
  dimred = "PCA",
  cell.group = NULL,
  tar.cell = NULL,
  tar.bulk = NULL,
  size.pt = 1,
  alpha.pt = 0.8,
  shape = NULL,
  col.idp = FALSE,
  decon = FALSE,
  profile = TRUE,
  charcoal = FALSE,
  alpha.overlay = 1,
  lay.shm = "gene",
  ncol = 2,
  h = 0.99,
  size.r = 1,
  col.com = c("yellow", "orange", "red"),
  col.bar = "selected",
  thr = c(NA, NA),
  cores = NA,
  bar.width = 0.08,
  bar.title = NULL,
  bar.title.size = 0,
  scale = "no",
  ft.trans = NULL,
  tis.trans = ft.trans,
  legend.r = 0,
  lgd.plots.size = NULL,
  sub.title.size = 11,
  sub.title.vjust = 3,
  legend.plot = "all",
  ft.legend = "identical",
  bar.value.size = 10,
  legend.plot.title = "Legend",
  legend.plot.title.size = 11,
  legend.ncol = NULL,
  legend.nrow = NULL,
  legend.position = "bottom",
  legend.direction = NULL,
  legend.key.size = 0.02,
  legend.text.size = 12,
  angle.text.key = NULL,
  position.text.key = NULL,
  legend.2nd = FALSE,
  position.2nd = "bottom",
  legend.nrow.2nd = 2,
  legend.ncol.2nd = NULL,
  legend.key.size.2nd = 0.03,
  legend.text.size.2nd = 10,
  angle.text.key.2nd = 0,
  position.text.key.2nd = "right",
  dim.lgd.pos = "bottom",
  dim.lgd.nrow = 2,
  dim.lgd.key.size = 4,
  dim.lgd.text.size = 13,
  dim.axis.font.size = 8,
  dim.capt.size = 13,
  size.lab.pt = 5,
  hjust.lab.pt = 0.5,
  vjust.lab.pt = 1.5,
  add.feature.2nd = FALSE,
  label = FALSE,
  label.size = 4,
  label.angle = 0,
  hjust = 0,
  vjust = 0,
  opacity = 1,
  key = TRUE,
  line.width = 0.2,
  line.color = "grey70",
  relative.scale = NULL,
  out.dir = NULL,
  animation.scale = 1,
  selfcontained = FALSE,
  aspr = 1,
  video.dim = "640x480",
  res = 500,
  interval = 1,
  framerate = 1,
  bar.width.vdo = 0.1,
  legend.value.vdo = NULL,
  verbose = TRUE,
  ...
)

Arguments

svg.path

File paths of aSVG files.

bulk, cell

File paths of bulk and single cell data that are saved with saveRDS respectively.

match.lis

The file path of matching list that is saved with saveRDS. See match in SPHM.

assay.na

The name of target assay to use when data is SummarizedExperiment.

sam.factor

The column name corresponding to spatial features in colData of SummarizedExperiment. If the column names in the assay slot already follows the scheme "spatialFeature__variable", then the colData slot is not required and accordingly this argument could be NULL.

con.factor

The column name corresponding to experimental variables in colData of SummarizedExperiment. It can be NULL if column names of in the assay slot already follows the scheme "spatialFeature__variable", or no variable is associated with the data.

aggr

Aggregate "sample__condition" replicates by "mean" or "median". The default is "mean". If the data argument is a SummarizedExperiment, the "sample__condition" replicates are internally formed by connecting samples and conditions with "__" in colData slot, and are subsequently replace the original column names in assay slot. If no condition specified to con.factor, the data are aggregated by sample replicates. If "none", no aggregation is applied.

ID

A character vector of assyed items (e.g. genes, proteins) whose abudance values are used to color the aSVG.

var.cell

The column name in the colData slot of SingleCellExperiment that indicates the experimental variables. If NULL, no variables are considered.

dimred

One of PCA, UMAP, TSNE in sce.dimred, specifying which reduced dimension to use in co-visualization plots.

cell.group

Applicable when co-visualizing bulk and single-cell data with cell grouping methods of annodation labels, marker genes, clustering, or manual assignments. A column name in colData(sce.dimred), where one label defines a cell group.

tar.cell

Applicable when co-visualizing bulk and single-cell data with cell-to-bulk mapping. A vector of cell group labels in cell.group which are mapped to tissues through lis.rematch. Cells corresponding to these labels will be colored in the embedding plot while other cells will be grey, and tissues corresponding to these labels will be colored in the SHM while other tissues will be transparent.

tar.bulk

A vector of tissues of interest, which are mapped to single cells through cell group labels with lis.rematch. These tissues will be colored in SHMs while other tissues will be transparent, and cells corresponding to these tissues will be colored embedding plots while other cells will be grey.

size.pt, alpha.pt

The size and alpha value of points in the embedding plot respectively.

shape

A named numeric vector of custom shapes for points in the embedding plot, where the names are the cluster labels and values are from c(0, 2:25, 32:127).

col.idp

Logical, if TRUE, each cell in the embedding plot and spatial feature in the SHM are colored independently according the expression values of chosen biomolecules.

decon

Logical, if TRUE, the cell data will be considered from bulk deconvolution results.

profile

Logical, applicable when co-visualizing bulk and single-cell data. If TRUE, one or multiple biomolecule (e.g. gene) identifiers need to be assigned to ID, and their abundance proifles will be used for coloring in the co-visualization plots. If FALSE, constant colors will be used in the co-visualization plot.

charcoal

Logical, if TRUE the raster image will be turned black and white.

alpha.overlay

The opacity of the raster image under the SHM when superimposing raster images with SHMs. The default is 1.

lay.shm

One of 'gene', 'con', or 'none'. If 'gene', SHMs are organized horizontally by each biomolecule (gene, protein, or metabolite, etc.) and variables are sorted under each biomolecule. If 'con', SHMs are organized horizontally by each experiment vairable and biomolecules are sorted under each variable. If 'none', SHMs are organized by the biomolecule order in ID and variables follow the order they appear in data.

ncol

The number of columns to display SHMs, which does not include the legend plot.

h

The height (0-1) of color key and SHM/co-visualization plots in the middle, not including legend plots.

size.r

The scaling ratio (0-1) of tissue section when visualizing the spatially resolved single-cell data.

col.com

A vector of color components used to build the color scale. The default is ‘c(’yellow', 'orange', 'red')'.

col.bar

One of 'selected' or 'all', the former uses expression values of ID to build the color scale while the latter uses all expression values from the data. The default is 'selected'.

thr

A two-numeric vector of expression value thresholds (the range of the color bar). The first and the second element will be the minmun and maximum threshold in the color bar respectively. Values above the max or below min will be assigned the same color as the max or min respectively. The default is c(NA, NA) and the min and max values in the data will be used. If one needs to change only max or min, the other should be NA.

cores

The number of CPU cores for parallelization. The default is 'NA', and the number of used cores is 1 or 2 depending on the availability.

bar.width

The width of color bar that ranges from 0 to 1. The default is 0.08.

bar.title, bar.title.size

The title and title size of the color key.

scale

One of no (default), selected, all, or row, corresponding to no scaling, scaling selected rows as a whole, scaling all rows as a whole, or scaling each row independently.

ft.trans

A character vector of spatial features that will be set transparent. When features of interest are covered by overlapping features on the top layers and the latter can be set transparent.

tis.trans

This argument is deprecated and replaced by ft.trans.

legend.r

A numeric (-1 to 1) to adjust the legend plot size.

lgd.plots.size

A vector of 2 or 3 numeric values that sum up between 0 and 1 (e.g., 'c(0.5, 0.4)'), corresponding to the sizes of legend plots in the co-visualization plot. If there are 2 values, the first and second values correspond to the sizes of the SHM and embedding plots, respectively. If there are 3 values, the first, second, and third values correspond to the sizes of the SHM, single-cell SHM, and embedding plots, respectively.

sub.title.size

A numeric of the subtitle font size of each individual spatial heatmap. The default is 11.

sub.title.vjust

A numeric of vertical adjustment for subtitle. The default is 2.

legend.plot

A vector of suffix(es) of aSVG file name(s) such as c('shm1', 'shm2'). Only aSVG(s) whose suffix(es) are assigned to this arugment will have a legend plot on the right. The default is all and each aSVG will have a legend plot. If NULL, no legend plot is shown.

ft.legend

One of "identical", "all", or a character vector of tissue/spatial feature identifiers from the aSVG file. The default is "identical" and all the identical/matching tissues/spatial features between the data and aSVG file are colored in the legend plot. If "all", all tissues/spatial features in the aSVG are shown. If a vector, only the tissues/spatial features in the vector are shown.

bar.value.size

A numeric of value size in the y-axis of the color bar. The default is 10.

legend.plot.title

The title of the legend plot. The default is 'Legend'.

legend.plot.title.size

The title size of the legend plot. The default is 11.

legend.ncol

An integer of the total columns of keys in the legend plot. The default is NULL. If both legend.ncol and legend.nrow are used, the product of the two arguments should be equal or larger than the total number of shown spatial features.

legend.nrow

An integer of the total rows of keys in the legend plot. The default is NULL. It is only applicable to the legend plot. If both legend.ncol and legend.nrow are used, the product of the two arguments should be equal or larger than the total number of matching spatial features.

legend.position

the default position of legends ("none", "left", "right", "bottom", "top", "inside")

legend.direction

layout of items in legends ("horizontal" or "vertical")

legend.key.size

A numeric of the legend key size ("npc"), applicable to the legend plot. The default is 0.02.

legend.text.size

A numeric of the legend label size, applicable to the legend plot. The default is 12.

angle.text.key

Key text angle in legend plots. The default is NULL, equivalent to 0.

position.text.key

The position of key text in legend plots, one of 'top', 'right', 'bottom', 'left'. Default is NULL, equivalent to 'right'.

legend.2nd

Logical. If 'TRUE', the secondary legend is added to each SHM, which are the numeric values of each colored spatial features. The default its 'FALSE'. Only applies to the static image.

position.2nd

The position of the secondary legend in SHMs, one of 'top', 'right', 'bottom', 'left', or a two-component numeric vector. The default is 'bottom'. Applies to images and videos.

legend.nrow.2nd

An integer of rows of the secondary legend keys in SHMs. Applies to static images and videos.

legend.ncol.2nd

An integer of columns of the secondary legend keys in SHMs. Applies to static images and videos.

legend.key.size.2nd

A numeric of legend key size in SHMs. The default is 0.03. Applies to static images and videos.

legend.text.size.2nd

A numeric of the secondary legend text size in SHMs. The default is 10. Applies to static images and videos.

angle.text.key.2nd

Angle of the key text in the secondary legend in SHMs. Default is 0. Applies to static images and videos.

position.text.key.2nd

The position of key text in the secondary legend in SHMs, one of 'top', 'right', 'bottom', 'left'. Default is 'right'. Applies to static images and videos.

dim.lgd.pos

The position of legends in the embedding plot. One of top, right, bottom, and left.

dim.lgd.nrow

The number of rows in the embedding plot legends.

dim.lgd.key.size, dim.lgd.text.size

The key and font size of the embedding plot legends respectively.

dim.axis.font.size

The size of axis font of the embedding plot.

dim.capt.size

The size of caption text in the dimension reduction plot in co-clustering (see cocluster). The default is 13.

size.lab.pt

The size of point labels, applicable when decon=TRUE.

hjust.lab.pt, vjust.lab.pt

Numeric values to adjust the horizontal and vertical positions of point labels respectively, applicable when decon=TRUE.

add.feature.2nd

Logical. If 'TRUE', feature identifiers are added to the secondary legend. The default is FALSE. Applies to static images of SHMs.

label

Logical. If 'TRUE', the same spatial features between numeric data and aSVG are labeled by their identifiers. The default is 'FALSE'. It is useful when spatial features are labeled by similar colors.

label.size

The size of spatial feature labels in legend plots. The default is 4.

label.angle

The angle of spatial feature labels in legend plots. Default is 0.

hjust, vjust

The value to horizontally or vertically adjust positions of spatial feature labels in legend plots respectively. Default of both is 0.

opacity

The transparency of colored spatial features in legend plots. Default is 1. If 0, features are totally transparent.

key

Logical. If 'TRUE' (default), keys are added in legend plots. If label is TRUE, the keys could be removed.

line.width

The thickness of each shape outline in the aSVG is maintained in spatial heatmaps, i.e. the stroke widths in Inkscape. This argument is the extra thickness added to all outlines. Default is 0.2 in case stroke widths in the aSVG are 0.

line.color

A character of the shape outline color. Default is "grey70".

relative.scale

A numeric to adjust the relative sizes between multiple aSVGs. Applicable only if multiple aSVGs are provided. Default is NULL and all aSVGs have the same size.

out.dir

The directory to save SHMs as interactive HTML files and videos. Default is 'NULL', and the HTML files and videos are not saved.

animation.scale

A numeric to scale the SHM size in the HTML files. The default is 1, and the height is 550px and the width is calculated according to the original aspect ratio in the aSVG file.

selfcontained

Whether to save the HTML as a single self-contained file (with external resources base64 encoded) or a file with external resources placed in an adjacent directory.

aspr

The aspect ratio (width to height) in the interative HTML files.

video.dim

A single character of the dimension of video frame in form of 'widthxheight', such as '1920x1080', '1280x800', '320x568', '1280x1024', '1280x720', '320x480', '480x360', '600x600', '800x600', '640x480' (default). The aspect ratio of SHMs are decided by width and height.

res

Resolution of the video in dpi.

interval

The time interval (seconds) between SHM frames in the video. Default is 1.

framerate

An integer of video framerate in frames per seconds. Default is 1. Larger values make the video smoother.

bar.width.vdo

The color bar width (0-1) in videos.

legend.value.vdo

Logical. If 'TRUE', numeric values of colored spatial features are added to the video legend. The default is NULL.

verbose

Logical. If 'TRUE' (default), intermediate messages will be printed.

...

additional element specifications not part of base ggplot2. In general, these should also be defined in the ⁠element tree⁠ argument. Splicing a list is also supported.

Value

A 'SPHM' class.

Author(s)

Jianhai Zhang jzhan067@ucr.edu
Dr. Thomas Girke thomas.girke@ucr.edu

Examples


# Path of mouse brain aSVG.
svg.mus.brain.pa <- system.file("extdata/shinyApp/data", "mus_musculus.brain.svg", package="spatialHeatmap")
# Bulk data path.
blk.mus.pa <- system.file("extdata/shinyApp/data", "bulk_mouse_cocluster.rds", package="spatialHeatmap") 
# Plotting spatial heatmaps.
plot_meta(svg.path=svg.mus.brain.pa, bulk=blk.mus.pa, sam.factor='tissue', aggr='mean', ID=c('AI593442', 'Adora1'), ncol=1, bar.width=0.1, legend.nrow=5, h=0.6)


jianhaizhang/spatialHeatmap documentation built on July 31, 2024, 2:59 a.m.