plot_som: SOM

View source: R/plot_som.R

plot_somR Documentation

SOM

Description

This function plots the output of a self-organizing map.

Usage

plot_som(
  dat,
  type = "model",
  design = NULL,
  coef = NULL,
  stat = "lfc",
  sample = 1L,
  top = 0.5,
  grid_dims = NULL,
  topo = "hexagonal",
  neighb = "gaussian",
  rlen = 1000L,
  parallel = TRUE,
  pal_tiles = NULL,
  title = NULL,
  legend = "right",
  hover = FALSE,
  export = TRUE,
  ...
)

Arguments

dat

Either a probe by sample omic data matrix or an object of class kohonen.

type

What should the plot visualize? Options include "model", "sample", "distance", "counts", "quality", and "train". See Details.

design

Design matrix for linear model with rows corresponding to samples and columns to model coefficients. Only relevant if type = "model".

coef

Column number or name specifying which coefficient or contrast of the linear model is of interest. Only relevant if type = "model".

stat

Which nodewise summary statistic should be plotted in the SOM? Options are "lfc" or "t". Only relevant if type = "model".

sample

Column number or name specifying which sample should be plotted. Only relevant if type = "sample".

top

Optional number (if > 1) or proportion (if < 1) of most variable probes to be used for SOM.

grid_dims

Vector of length two specifying x- and y-axis dimensions for the SOM grid. If NULL, values are chosen so as to create a square grid with approximately 10 probes in each node, presuming a uniform distribution across the map.

topo

Train SOM using "hexagonal" or "rectangular" topology?

neighb

Train SOM using a "gaussian" or "bubble" neighborhood function?

rlen

Run length for SOM training.

parallel

Allow for parallel computation of SOM?

pal_tiles

String specifying the color palette to use for heatmap nodes. Defaults vary by type (see Details). Any divergent or sequential palette in RColorBrewer is acceptable. Alternatively, any vector of recognized colors may be supplied.

title

Optional plot title.

legend

Legend position. Must be one of "bottom", "left", "top", "right", "bottomright", "bottomleft", "topleft", or "topright".

hover

Show constituent probes by hovering mouse over module tile? If TRUE, the plot is rendered in HTML and will either open in your browser's graphic display or appear in the RStudio viewer.

export

Return fitted SOM model?

...

Additional arguments to be passed to lmFit if type = "model".

Details

A self-organizing map (SOM) is a type of neural network used for dimensionality reduction and data visualization. SOMs come in many flavors, but the kind used here clusters probes together in an unsupervised manner to identify functionally relevant gene sets, examine patterns across samples, and explore hypotheses. See the references below for more details on SOM algorithms and their applications for omic research.

If type = "model", then a linear model is fit to the codebook vectors. Units are colored either by each node's log fold change (if stat = "lfc") or moderated t-statistic as calculated by limma (if stat = "t") for a given model coefficient. Default color palette is "Spectral".

If type = "sample", then the plot depicts that sample's expression profile across the SOM. Default color palette is "Spectral".

If type = "distance", then the figure renders the SOM's U-matrix, which represents the Euclidean distance between codebook vectors for neighboring units. This can be used to inspect for clusters and borders in the SOM space. Default color palette is "Greys".

If type = "counts", then units are colored by each node's probe count. This distribution should ideally be nearly uniform. A large number of empty units suggests that grid_dims should be reduced; an uneven spread across the units suggests that grid_dims should be increased. Default color palette is "Blues".

If type = "quality", then nodes are colored by the mean distance of intra-unit probes from one another. Very large values or uneven distributions suggest the SOM may need more training iterations to reach a stable solution. Default color palette is "Reds".

If type = "train", then the plot displays the SOM's learning curve over its rlen training iterations.

Depending on the data's size, the model's parameters, and your computational resources, it may take a considerable amount of time to fit a SOM to an omic matrix. That is why plot_som returns the SOM object by default, which may in turn be reused in subsequent calls to the function to explore alternative aspects of the map. SOMs are trained using the batch algorithm of kohonen::som. This may be executed in parallel for faster mapping. See the package documentation for more details.

Value

If dat is an omic data matrix or matrix-like object and export = TRUE, then plot_som returns an object of class kohonen. This is a fitted SOM as generated by the kohonen package. See som for more details.

References

Kohonen, T. (1995). Self-Organizing Maps. Berlin: Springer-Verlag.

Nikkilä, J., Törönen, P., Kaski, S., Venna, J., Castrén, E., & Wong, G. (2002). Analysis and visualization of gene expression data using Self-Organizing Maps. Neural Networks, 15(8-9): 953-966.

Wehrens, R. & Buydens, L.M.C. (2007). Self- and Super-organizing Maps in R: The kohonen Package J. Stat. Softw., 21(5).

Wirth, H. (2012). Analysis of large-scale molecular biological data using self-organizing maps. Dissertation thesis, University of Leipzig.

See Also

som

Examples

mat <- matrix(rnorm(1000 * 5), nrow = 1000, ncol = 5)
plot_som(mat, type = "sample", sample = 1)


dswatson/bioplotr documentation built on March 3, 2023, 9:43 p.m.