Hotelling's T² Ellipses and Outlier Detection for 'ggplot2'

Calculate Hotelling's T² ellipses and detect multivariate outliers both for base R plots and 'ggplot2' plots. Optionally, uses robust covariance estimation to reduce the influence of outliers on the ellipses. Also included: bagplots, kernel density plots and outlier diagnostic plots.


Hotelling’s T² Ellipses and Outlier Detection for ggplot2

R-CMD-check Codecov testcoverage

Here are a few examples of plots you can create with gghotelling:

Features:

  • Classical Hotelling and data ellipses with geom_hotelling()
  • Robust Hotelling ellipses using MCD estimator with robust=TRUE
  • Hotelling confidence ellipses for group means with type="t2mean"
  • Kernel density coverage contours with geom_kde()
  • Outlier detection with outliers()
  • Outlier visualization with stat_outliers() and plot_outliers()
  • Convex hulls with geom_hull()
  • Bagplots with geom_bag()
  • Autoplot and autolayer methods for prcomp objects

See the vignette for more details.

Installation

You can install the development version of gghotelling from GitHub with:

# install.packages("pak")
pak::pak("january3/gghotelling")

Minimal Example

The package defines a new geom, geom_hotelling(), which can be used to add Hotelling ellipses to ggplot2 scatter plots. Here are two examples of usage:

library(ggplot2)
library(gghotelling)

pca <- prcomp(iris[, 1:4], scale.=TRUE)
df <- cbind(iris, pca$x)

# minimum example
p1 <- ggplot(df, aes(PC1, PC2, color=Species)) +
  geom_hotelling() +
  geom_point()

# set custom CI/coverage level
p2 <- ggplot(df, aes(PC1, PC2, color=Species)) +
  geom_hotelling(alpha=0.1, aes(fill = Species), level=.99) +
  geom_point()

cowplot::plot_grid(p1, p2, ncol=2)

AI and other tools disclosure

I used LLM modes to a) detect bugs, spelling errors, clerical mistakes and other deficiencies in the code and b) better understand the ggplot2 specific code (especially after_stat()).

Furthermore, I used devtools, checktor and covr.

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.

install.packages("gghotelling")

0.2.1 by January Weiner, 2 months ago


https://github.com/january3/gghotelling/, https://january3.github.io/gghotelling/


Browse source code at https://github.com/cran/gghotelling


Authors: January Weiner [aut, cre, cph] (ORCID:


Documentation:   PDF Manual  


MIT + file LICENSE license


Imports ggplot2, grDevices, MASS, mrfDepth, robustbase

Suggests testthat, ggrepel, knitr, rmarkdown, HDclassif, spelling, cowplot


See at CRAN