Author: Guangchuang Yu School of Basic Medical Sciences, Southern Medical University
Date: 2025-07-25

# Unify Dimensionality Reduction Results

#### Guangchuang Yu
School of Basic Medical Sciences, Southern Medical University

#### 2025-07-25

## Interface for dimensionality reduction methods

    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()

    ## The `dr()` function works for the following methods that
    ## require data matrix (or data frame) as input:
    ##   +  stats::prcomp()
    ##   +  Rtsne::Rtsne()
    ##   +  uwot::umap()
    ##   +  uwot::tumap()
    ##   +  uwot::lvish()

    ## The `dr()` function works for the following methods that
    ## require distance matrix (or distance object) as input:
    ##   +  stats::cmdscale()
    ##   +  MASS::sammon()
    ##   +  vegan::metaMDS()
    ##   +  ape::pcoa()
    ##   +  smacof::mds()
    ##   +  vegan::wcmdscale()
    ##   +  ecodist::pco()
    ##   +  labdsv::pco()
    ##   +  ade4::dudi.pco()

## 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()

    ## Warning: `aes_()` was deprecated in ggplot2 3.0.0.
    ## ℹ Please use tidy evaluation idioms with `aes()`
    ## ℹ The deprecated feature was likely used in the tidydr package.
    ##   Please report the issue at <https://github.com/YuLab-SMU/tidydr/issues>.
    ## This warning is displayed once every 8 hours.
    ## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
    ## generated.