8.1 Uniform Manifold Approximation and Projection (UMAP)

To run UMAP in ArchR we use the addUMAP() function:

projHeme2 <- addUMAP(
    ArchRProj = projHeme2, 
    reducedDims = "IterativeLSI", 
    name = "UMAP", 
    nNeighbors = 30, 
    minDist = 0.5, 
    metric = "cosine"
)
## 06:21:02 UMAP embedding parameters a = 0.583 b = 1.334
## 06:21:02 Read 10250 rows and found 30 numeric columns
## 06:21:02 Using Annoy for neighbor search, n_neighbors = 30
## 06:21:02 Building Annoy index with metric = cosine, n_trees = 50
## 0%   10   20   30   40   50   60   70   80   90   100%
## [----|----|----|----|----|----|----|----|----|----|
## **************************************************|
## 06:21:03 Writing NN index file to temp file /tmp/Rtmp5J9pWv/file371b020ab5662
## 06:21:03 Searching Annoy index using 64 threads, search_k = 3000
## 06:21:03 Annoy recall = 100%
## 06:21:05 Commencing smooth kNN distance calibration using 64 threads
## 06:21:07 Initializing from normalized Laplacian + noise
## 06:21:07 Commencing optimization for 200 epochs, with 466722 positive edges
## 06:21:13 Optimization finished
## 06:21:13 Creating temp model dir /tmp/Rtmp5J9pWv/dir371b067c39752
## 06:21:13 Creating dir /tmp/Rtmp5J9pWv/dir371b067c39752
## 06:21:14 Changing to /tmp/Rtmp5J9pWv/dir371b067c39752
## 06:21:14 Creating /corces/home/rcorces/scripts/github/ArchR_Website_Testing/bookdown/Save-ProjHeme1/Embeddings/Save-Uwot-UMAP-Params-IterativeLSI-371b04f188bb0-Date-2022-12-23_Time-06-21-13.tar

You can list the available embeddings objects in an ArchRProject using the slot extraction opperator @:

projHeme2@embeddings
## List of length 1
## names(1): UMAP

To plot the UMAP results, we use the plotEmbedding() function and pass the name of the UMAP embedding we just generated (“UMAP”). We can tell ArchR how to color the cells by using a combination of colorBy which tells ArchR which matrix to use to find the specified metadata column provided to name.

p1 <- plotEmbedding(ArchRProj = projHeme2, colorBy = "cellColData", name = "Sample", embedding = "UMAP")
## ArchR logging to : ArchRLogs/ArchR-plotEmbedding-371b05863fb62-Date-2022-12-23_Time-06-21-15.log
## If there is an issue, please report to github with logFile!
## Getting UMAP Embedding
## ColorBy = cellColData
## Plotting Embedding
## 1 
## ArchR logging successful to : ArchRLogs/ArchR-plotEmbedding-371b05863fb62-Date-2022-12-23_Time-06-21-15.log

Instead of coloring by “Sample” as above, we can color by “Clusters” which were identified in a previous chapter.

p2 <- plotEmbedding(ArchRProj = projHeme2, colorBy = "cellColData", name = "Clusters", embedding = "UMAP")
## ArchR logging to : ArchRLogs/ArchR-plotEmbedding-371b030854ddb-Date-2022-12-23_Time-06-21-17.log
## If there is an issue, please report to github with logFile!
## Getting UMAP Embedding
## ColorBy = cellColData
## Plotting Embedding
## 1 
## ArchR logging successful to : ArchRLogs/ArchR-plotEmbedding-371b030854ddb-Date-2022-12-23_Time-06-21-17.log

We can visualize these two plots side by side using the ggAlignPlots() function, specifying a horizontal orientation using type = "h".

ggAlignPlots(p1, p2, type = "h")

To save an editable vectorized version of this plot, we use plotPDF().

plotPDF(p1,p2, name = "Plot-UMAP-Sample-Clusters.pdf", ArchRProj = projHeme2, addDOC = FALSE, width = 5, height = 5)
## Plotting Ggplot!
## Plotting Ggplot!

We can also use plotEmbedding() to visualize the results from clustering using scran:

p1 <- plotEmbedding(ArchRProj = projHeme2, colorBy = "cellColData", name = "Sample", embedding = "UMAP")
## ArchR logging to : ArchRLogs/ArchR-plotEmbedding-371b02512d50-Date-2022-12-23_Time-06-21-26.log
## If there is an issue, please report to github with logFile!
## Getting UMAP Embedding
## ColorBy = cellColData
## Plotting Embedding
## 1 
## ArchR logging successful to : ArchRLogs/ArchR-plotEmbedding-371b02512d50-Date-2022-12-23_Time-06-21-26.log
p2 <- plotEmbedding(ArchRProj = projHeme2, colorBy = "cellColData", name = "ScranClusters", embedding = "UMAP")
## ArchR logging to : ArchRLogs/ArchR-plotEmbedding-371b0706c115a-Date-2022-12-23_Time-06-21-28.log
## If there is an issue, please report to github with logFile!
## Getting UMAP Embedding
## ColorBy = cellColData
## Plotting Embedding
## 1 
## ArchR logging successful to : ArchRLogs/ArchR-plotEmbedding-371b0706c115a-Date-2022-12-23_Time-06-21-28.log
ggAlignPlots(p1, p2, type = "h")

To save an editable vectorized version of this plot, we use plotPDF().

plotPDF(p1,p2, name = "Plot-UMAP-Sample-ScranClusters.pdf", ArchRProj = projHeme2, addDOC = FALSE, width = 5, height = 5)
## Plotting Ggplot!
## Plotting Ggplot!