Unify Dimensionality Reduction Results

knitr::opts_chunk$set(tidy = FALSE,
           message = FALSE)

Interface for dimensionality reduction methods

library(ggplot2)
library(tidydr) 
library(tidydr)
x <- dr(data = iris[,1:4], fun = prcomp)

The dr() function apply the function, fun, and (if any) parameters to analyze the input 'data'.

The data can be original data matrix (or data frame), or distance matrix (or distance object), depending on the requirement of the DR method (specify by the 'fun' parameter).

Methods supported by the dr() function can be listed via the available_methods():

available_methods()

Visualization

The tidydr package extends ggplot() to support the output of dr() function.

Associated data (e.g., group information) can be integrated to scale the color, shape or size of data points. The data should be provided via the metadata parameter. It allows a vector (will be stored in .group) or a data frame.

library(ggplot2)
## metadata as a vector
ggplot(x, aes(Dim1, Dim2), metadata=iris$Species) + 
  geom_point(aes(color=.group))

Users can use autoplot() as a shortcut. This package provide a theme, theme_dr(), to allow using shorten axes.

## metadata as a data frame
autoplot(x, aes(color=Species), metadata = iris[, 5, drop=FALSE]) +
  theme_dr()


Try the tidydr package in your browser

Any scripts or data that you put into this service are public.

tidydr documentation built on March 31, 2023, 6:50 p.m.