dimr | R Documentation |
Wrapper function to perform and plot methods of dimensionality reduction
including Rtsne
, rpca
,
prcomp
, andumap
, with optional
kmeans
clustering.
dimr(data, type = c("tsne", "pca", "rpca", "umap"), k = NULL, ...)
## S3 method for class 'dimr'
plot(
x,
group = TRUE,
group2 = NULL,
k = NULL,
col = NULL,
labels = FALSE,
vegan = FALSE,
loadings = 0L,
legend = TRUE,
args.legend = list(),
plot3d = FALSE,
iplot = FALSE,
...
)
data |
an |
type |
the type of algorithm to run |
k |
an integer representing the number of desired clusters, passed to
note, if |
... |
for |
x |
an object of class |
group |
a length |
group2 |
a list of data to plot, usually samples in |
col |
a vector of colors for each group |
labels |
argument controlling labels for points; if |
vegan |
logical; if |
loadings |
for PCA objects, a length 1 or 2 vector giving the number of loadings to plot for each component; the highest loadings will be shown as a proportion of the axes with the sign of the eigenvector |
legend |
logical; if |
args.legend |
a named list of |
plot3d |
logical; if |
iplot |
logical; if |
dimr
returns a list of class "dimr
" with the following
components:
object |
the object return by the algorithm determined via
|
x |
a matrix with the first three dimensions |
kmeans |
a k-means clustering performed on the first two
dimensions of |
Rtsne
; rpca
;
prcomp
; umap
,
kmeans
## feature x sample matrix
dat <- t(unique(iris[, 1:4]))
grp <- unique(iris)$Species
tsne <- dimr(dat)
umap <- dimr(dat, type = 'umap')
pca <- dimr(dat, type = 'pca')
rpca <- dimr(dat, type = 'rpca')
pca2 <- dimr(dat, type = 'pca', scale. = TRUE) ## same as rpca
plot(tsne) ## use k-means cluster groups
plot(tsne, grp) ## use groups from data
plot(tsne, k = 3) ## perform new k-means
plot(pca, vegan = TRUE)
plot(pca, loadings = c(3, 4))
plot(rpca, loadings = c(3, 4))
plot(pca, k = 4, vegan = TRUE)$kmeans$cluster
## use group2 to show scatter plots of numeric data
plot(pca, group2 = as.list(data.frame(t(dat))))
plot(pca, pch = 16, cex = 3, col = adjustcolor(palette()[1:3], alpha.f = 0.5),
group2 = as.list(data.frame(t(rbind(dat, dat)))))
## use plot3d = TRUE for a 3D, interactive figure
## Not run:
plot(tsne, plot3d = TRUE)
plot(tsne, iplot = TRUE, labels = data.frame(t(dat)))
## make a gridplot (called from plot.dimr)
n <- 9
d <- as.list(mtcars[, rep_len(c('mpg', 'wt', 'hp'), n)])
par(mfrow = n2mfrow(n), oma = c(5, 5, 4, 2))
plotr:::gridplot(d, mtcars$mpg, mtcars$wt, legend = TRUE)
title(xlab = 'MPG', ylab = 'Weight', outer = TRUE, cex.lab = 2)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.