| fviz_umap | R Documentation |
fviz_umap() and fviz_tsne() draw a ggplot2 scatter plot of a
two-dimensional embedding produced by UMAP or t-SNE, with
factoextra's grouping, ellipse and palette styling. They accept the result of
uwot::umap() / umap::umap() / Rtsne::Rtsne(), or a plain
matrix / data frame of coordinates.
Unlike PCA, an embedding has no eigenvalues: the axes explain no fixed
percentage of variance, so they are labelled UMAP1/UMAP2
(tSNE1/tSNE2) without a percentage, and there is deliberately no
scree plot, no variable loadings, and no correlation circle - those are
meaningless for an embedding. For methods that do have eigenvalues (PCA,
CA, MCA, MDS) see fviz_pca and as_factoextra_pca.
Read more: UMAP in R: Nonlinear Dimension Reduction & Visualization and t-SNE in R: Visualize High-Dimensional Data.
fviz_umap(
X,
dims = c(1L, 2L),
habillage = NULL,
col.ind = NULL,
geom = "point",
label = FALSE,
pointsize = 1.5,
labelsize = 4,
addEllipses = FALSE,
ellipse.type = "convex",
ellipse.level = 0.95,
mean.point = FALSE,
palette = NULL,
gradient.cols = NULL,
density = FALSE,
facet.by = NULL,
repel = TRUE,
max.points = NULL,
sample.seed = 123,
legend.title = NULL,
caption = NULL,
ggtheme = theme_minimal(),
...
)
fviz_tsne(
X,
dims = c(1L, 2L),
habillage = NULL,
col.ind = NULL,
geom = "point",
label = FALSE,
pointsize = 1.5,
labelsize = 4,
addEllipses = FALSE,
ellipse.type = "convex",
ellipse.level = 0.95,
mean.point = FALSE,
palette = NULL,
gradient.cols = NULL,
density = FALSE,
facet.by = NULL,
repel = TRUE,
max.points = NULL,
sample.seed = 123,
legend.title = NULL,
caption = NULL,
ggtheme = theme_minimal(),
...
)
X |
an embedding: a |
dims |
two distinct positive integer indices specifying which embedding dimensions to plot. |
habillage |
an optional factor / vector used to colour the points by group (discrete). Its length must equal the number of embedded observations. |
col.ind |
point colour: a factor / character vector (discrete groups) or a
numeric vector to colour by a continuous feature value (as in a
Seurat feature plot). A single colour name is also allowed. The eigenvalue
metrics accepted by |
geom |
character: |
label |
logical; if |
pointsize, labelsize |
point and label size. |
addEllipses |
logical; if |
ellipse.type, ellipse.level |
ellipse type and confidence level. See
|
mean.point |
logical; if |
palette, gradient.cols |
discrete group palette / continuous colour
gradient, passed to |
density |
logical; if |
facet.by |
optional variable (length = number of observations) to facet by. |
repel |
logical; if |
max.points, sample.seed |
passed to the downsampling used for large
embeddings; see |
legend.title |
colour legend title. Defaults to |
caption |
optional plot caption (e.g. an interpretation reminder). Off by default. |
ggtheme, ... |
passed to |
UMAP and t-SNE produce a low-dimensional embedding, not a variance
decomposition. Local relationships are often more informative than global
geometry, but both remain method- and parameter-dependent. In particular, the
size of a cluster, the distance between well-separated
clusters, and the amount of empty space between them are not quantitatively
meaningful and change with perplexity or n_neighbors
(Wattenberg et al., 2016). Similar embedding scatter plots are drawn by Seurat::DimPlot()
/ FeaturePlot() and ggpca.
a ggplot2 object.
McInnes, L., Healy, J. and Melville, J. (2018). UMAP: Uniform Manifold Approximation and Projection for Dimension Reduction. arXiv:1802.03426.
Wattenberg, M., ViƩgas, F. and Johnson, I. (2016). How to Use t-SNE Effectively. Distill. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.23915/distill.00002")}.
fviz_pca, as_factoextra_pca,
fviz_cluster.
Online tutorials: UMAP in R: Nonlinear Dimension Reduction & Visualization
and t-SNE in R: Visualize High-Dimensional Data.
if (requireNamespace("uwot", quietly = TRUE)) {
set.seed(123)
um <- uwot::umap(iris[, 1:4], n_neighbors = 15)
fviz_umap(um, habillage = iris$Species, addEllipses = TRUE)
# colour by a continuous feature value
fviz_umap(um, col.ind = iris$Petal.Length)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.