EmbedSOM basic embedding

Mirek Kratochvil

2020-01-18

Basic embedding with EmbedSOM

Dataset

We will embed a small dataset created from gaussian clusters positioned in vertices of a 5-dimensional hypercube.

This looks relatively nicely from the side (each corner in fact hides 8 separate clusters):

Linear dimensionality reduction doesn’t help much with seeing all 32 clusters:

Let’s use the non-linear EmbedSOM instead.

Getting the SOM ready

EmbedSOM works on a self-organizing map that you need to create first:

EmbedSOM provides some level of compatibility with FlowSOM that can be used to simplify some commands. FlowSOM-originating maps and whole FlowSOM object may be used as well:

\(24\times24\) is the recommended SOM size for getting something interesting from EmbedSOM – it provides a good amount of detail, and still runs quite quickly.

Embedding

When the SOM is ready, a matrix of 2-dimensional coordinates is obtained using the EmbedSOM function:

Alternatively, FlowSOM objects are supported to be used instead of data and map parameters in most EmbedSOM commands:

Several extra parameters may be specified; e.g. the following code makes the embedding a bit smoother and faster (but not necessarily better). See the EmbedSOM paper for details on parameters.

Finally, e now contains the dimensionality-reduced 2D coordinates of the original data that can be used for plotting.

##      EmbedSOM1 EmbedSOM2
## [1,]  23.47801  13.42236
## [2,]  22.86703  12.98544
## [3,]  23.63919  14.31299
## [4,]  21.65178  12.51104
## [5,]  22.58825  13.94369
## [6,]  23.12144  13.64124

Plotting the data

The embedding can be plotted using the standard graphics function, nicely showing all clusters next to each other.

EmbedSOM provides specialized plotting function which is useful in many common use cases; for example for displaying density:

Or for seeing colored expression of a single marker (value=1 specifies a column number; column names can be used as well):

(Notice that it is necessary to pass in the original data frame. When working with FlowSOM, the same can be done using fsom=fs.)

Or multiple markers:

Or perhaps for coloring the clusters. The following example uses the FlowSOM-style clustering to find the original 32 clusters in the scattered data. If that works right, each cluster should have its own color. (See FlowSOM documentation on how the meta-clustering works.)

Custom colors are also supported (this is colored according to the dendrogram order):

ggplot2 interoperability is provided using function PlotGG:

(You may also get the ggplot-compatible data object using PlotData function.)