umapr wraps the Python implementation of UMAP to make the algorithm accessible from within R. It uses the great reticulate package.

Uniform Manifold Approximation and Projection (UMAP) is a non-linear dimensionality reduction algorithm. It is similar to t-SNE but computationally more efficient. UMAP was created by Leland McInnes and John Healy (github, arxiv).

Recently, two new UMAP R packages have appeared. These new packages provide more features than umapr does and they are more actively developed. These packages are:

  • umap, which provides the same Python wrapping function as umapr and also an R implementation, removing the need for the Python version to be installed. It is available on CRAN.

  • uwot, which also provides an R implementation, removing the need for the Python version to be installed.

Contributors

Angela Li, Ju Kim, Malisa Smith, Sean Hughes, Ted Laderas

umapr is a project that was first developed at rOpenSci Unconf 2018.

Installation

First, you will need to install Python and the UMAP package. Instruction available here.

Then, you can install the development version from GitHub with:

Basic use

Here is an example of running UMAP on the iris data set.

umap returns a data.frame with two attached columns called “UMAP1” and “UMAP2”. These columns represent the UMAP embeddings of the data, which are column-bound to the original data frame.

There is a function called run_umap_shiny() which will bring up a Shiny app for exploring different colors of the variables on the umap plots.

run_umap_shiny(embedding)

Shiny App for Exploring Results

Function parameters

There are a few important parameters. These are fully described in the UMAP Python documentation.

The n_neighbor argument can range from 2 to n-1 where n is the number of rows in the data.

The min_dist argument can range from 0 to 1.

The distance argument can be many different distance functions.

Comparison to t-SNE and principal components analysis

t-SNE and UMAP are both non-linear dimensionality reduction methods, in contrast to PCA. Because t-SNE is relatively slow, PCA is sometimes run first to reduce the dimensions of the data.

We compared UMAP to PCA and t-SNE alone, as well as to t-SNE run on data preprocessed with PCA. In each case, the data were subset to include only complete observations. The code to reproduce these findings are available in timings.R.

The first data set is the same iris data set used above (149 observations of 4 variables):

t-SNE, PCA, and UMAP on iris

Next we tried a cancer data set, made up of 699 observations of 10 variables:

t-SNE, PCA, and UMAP on cancer

Third we tried a soybean data set. It is made up of 531 observations and 35 variables:

t-SNE, PCA, and UMAP on soybeans

Finally we used a large single-cell RNAsequencing data set, with 561 observations (cells) of 55186 variables (over 30 million elements)!

t-SNE, PCA, and UMAP on rna

PCA is orders of magnitude faster than t-SNE or UMAP (not shown). UMAP, though, is a substantial improvement over t-SNE both in terms of memory and time taken to run.

Time to run t-SNE vs UMAP

Memory to run t-SNE vs UMAP