Skip to contents
  • wrap_hull() computes convex hull of a set of observations.


wrap_hull(x, ...)

  mapping = NULL,
  data = NULL,
  geom = "polygon",
  position = "identity",
  na.rm = FALSE,
  show.legend = NA,
  inherit.aes = TRUE,

# S4 method for MultivariateAnalysis
wrap_hull(x, margin = 1, axes = c(1, 2), group = NULL)

# S4 method for BootstrapPCA
wrap_hull(x, axes = c(1, 2))



An object from which to wrap observations (a CA or PCA object).


Currently not used.


Set of aesthetic mappings created by aes() or aes_(). If specified and inherit.aes = TRUE (the default), it is combined with the default mapping at the top level of the plot. You must supply mapping if there is no plot mapping.


The data to be displayed in this layer. There are three options:

If NULL, the default, the data is inherited from the plot data as specified in the call to ggplot().

A data.frame, or other object, will override the plot data. All objects will be fortified to produce a data frame. See fortify() for which variables will be created.

A function will be called with a single argument, the plot data. The return value must be a data.frame, and will be used as the layer data. A function can be created from a formula (e.g. ~ head(.x, 10)).


The geometric object to use display the data


Position adjustment, either as a string, or the result of a call to a position adjustment function.


A logical scalar: should missing values be silently removed? If FALSE (the ), missing values are removed with a warning.


logical. Should this layer be included in the legends? NA, the default, includes if any aesthetics are mapped. FALSE never includes, and TRUE always includes. It can also be a named logical vector to finely select the aesthetics to display.


If FALSE, overrides the default aesthetics, rather than combining with them. This is most useful for helper functions that define both data and aesthetics and shouldn't inherit behaviour from the default plot specification, e.g. borders().


A length-one numeric vector giving the subscript which the data will be returned: 1 indicates individuals/rows (the default), 2 indicates variables/columns.


A length-two numeric vector giving the dimensions to be for which to compute results.


A vector specifying the group an observation belongs to.


  • stat_hull() return a ggplot2::layer().

  • wrap_hull() return a data.frame of envelope principal coordinates. An extra column named group is added specifying the group an observation belongs to.

See also


N. Frerebeau


## Load data

## Compute principal components analysis
X <- pca(iris, scale = TRUE)
#> 1 qualitative variable was removed: Species.

## Plot results
plot_rows(X, colour = "group", group = iris$Species) +

## Convex hull coordinates
hulls <- wrap_hull(X, group = iris$Species)
#>                  F1          F2  group
#> setosa.32 -1.831595  0.42369507 setosa
#> setosa.24 -1.818670  0.08555853 setosa
#> setosa.42 -1.858122 -2.33741516 setosa
#> setosa.14 -2.633101 -0.96150673 setosa
#> setosa.23 -2.774345  0.45834367 setosa
#> setosa.33 -2.614948  1.79357586 setosa

## Plot with convex hulls
plot_rows(X, colour = "group", group = iris$Species) +
  stat_hull(geom = "path") +