pca_plot: Make a PCA/tSNE/UMAP plot

View source: R/pca_plot.r

pca_plotR Documentation

Make a PCA/tSNE/UMAP plot

Description

The function allows the passing of some parameters to Rtsne/umap:

  • Rtsne: perplexity

  • umap: nn (number of neighbors)

Usage

pca_plot(
  X,
  grp,
  txt = FALSE,
  method = c("pca", "tsne", "umap"),
  dims = 2,
  gg = TRUE,
  ellipse = FALSE,
  legend,
  repel = FALSE,
  plot = TRUE,
  ...
)

Arguments

X

A numeric matrix

grp

Optional grouping factor to color instances by

txt

Use rownames as labels instead of dots (default: false)

method

How to carry out dimension reduction (pca/tsne/umap)

dims

Dimensions to return (for tsne)

gg

Use ggplot2? (default: true)

ellipse

Draw mvn-ellipses around groups? (default: false, only available for ggplot)

legend

Include a legend (default: true)

repel

If gg=TRUE and txt=TRUE, use ggrepel::geom_text_repel()? (default: false)

plot

Create plot? (default: true)

...

Further arguments to plot()

Value

If base plot, returns PCA object invisibly. If ggplot, returns the plot object.

Examples

# Plots of the iris data
pca_plot(iris[,1:4])
pca_plot(iris[,1:4], grp=iris[,5])
pca_plot(iris[,1:4], grp=iris[,5], ellipse=TRUE)
pca_plot(iris[,1:4], grp=iris[,5], method='tsne')
pca_plot(iris[,1:4], grp=iris[,5], method='umap')

# What pca_plot returns if plot=FALSE
head(pca_plot(iris[,1:4], method='pca', plot=FALSE))
head(pca_plot(iris[,1:4], method='tsne', dims=3, plot=FALSE))
head(pca_plot(iris[,1:4], method='umap', dims=3, plot=FALSE))

# Plots of the USArrests data
pca_plot(USArrests, txt=TRUE)
pca_plot(USArrests, txt=TRUE, repel=TRUE)
pca_plot(USArrests, txt=TRUE, grp=rep(LETTERS[1:5], each=10))
pca_plot(USArrests, txt=TRUE, method='tsne', perplexity=10)
pca_plot(USArrests, txt=TRUE, method='umap', nn=6)

pbreheny/breheny documentation built on April 26, 2024, 10:40 a.m.