Skip to content

Instantly share code, notes, and snippets.

@daenuprobst
Last active November 17, 2025 10:29
Show Gist options
  • Select an option

  • Save daenuprobst/fe8d2dd75a986a1505e1fb4c326e4006 to your computer and use it in GitHub Desktop.

Select an option

Save daenuprobst/fe8d2dd75a986a1505e1fb4c326e4006 to your computer and use it in GitHub Desktop.
Simple UMAP example with parameters in R
---
title: "umap_example"
output: html_document
---
```{r setup}
library(uwot)
library(ggplot2)
```
```{r message=FALSE, warning=FALSE}
data(iris)
iris_features <- iris[, 1:4]
iris_labels <- iris$Species
umap_embeddings <- umap(iris_features, n_neighbors = 15, n_components = 2,
min_dist = 0.5, metric = "euclidean")
df <- data.frame(UMAP1 = umap_embeddings[,1],
UMAP2 = umap_embeddings[,2],
Species = iris_labels)
ggplot(df, aes(x = UMAP1, y = UMAP2, color = Species)) +
geom_point(size = 3, alpha = 0.8) +
ggtitle("UMAP of the Iris data set") +
theme_bw()
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment