- x
numeric matrix or data frame. In the function fviz_nbclust(), x can
be the results of the function NbClust(). For method = "silhouette"
or "wss", x may also be a precomputed dissimilarity (an object of
class "dist"); it is then passed directly to FUNcluster,
which must be a dissimilarity-capable method (e.g. cluster::pam or
factoextra::hcut). method = "gap_stat" still needs the raw data.
- FUNcluster
a partitioning function which accepts as first argument a
(data) matrix like x, second argument, say k >= 2, the
number of clusters desired, and returns a list with a component named
cluster which contains the grouping of observations. Allowed values
include: kmeans, cluster::pam, cluster::clara,
cluster::fanny, hcut, etc. In method = "wss" mode,
fviz_nbclust() computes the k = 1 baseline internally instead
of calling FUNcluster(x, 1, ...). This argument is not required
when x is an output of the function NbClust::NbClust().
- method
the method to be used for estimating the optimal number of
clusters. Possible values are "silhouette" (for average silhouette width),
"wss" (for total within-cluster sum of squares), and "gap_stat" (for the gap statistic).
- diss
dist object as produced by dist(), i.e.: diss = dist(x, method =
"euclidean"). Used to compute the average silhouette width and
within-cluster sum of squares. If NULL, dist(x) is
computed with the default method = "euclidean"
- k.max
the maximum number of clusters to consider, must be at least two.
- nboot
integer, number of Monte Carlo ("bootstrap") samples. Used only for determining the number of clusters
using the gap statistic.
- verbose
logical value. If TRUE, progress information is printed.
- barfill, barcolor
fill color and outline color for bars
- linecolor
color for lines
- print.summary
logical value. If TRUE, the optimal number of clusters
is printed in fviz_nbclust().
- ...
optionally further arguments:
arguments for FUNcluster() in "wss"/"silhouette" modes; arguments for
clusGap() in "gap_stat" mode. A maxSE list
can also be supplied in "gap_stat" mode and is forwarded to
fviz_gap_stat().
- mark_optimal
logical, or NULL (default). NULL keeps each
method's standard marker: a dashed guide line at the estimated optimal number
of clusters is drawn for method = "silhouette" (maximum average
silhouette width) and method = "gap_stat" (the
maxSE location), and omitted for method = "wss".
Set TRUE to also mark the "wss" elbow (a maximum-distance
heuristic that returns a candidate even when the data has no clear cluster
structure; see Details), or FALSE to omit the guide line for every
method.
- gap_stat
an object of class "clusGap" returned by the function
clusGap() [in cluster package]
- maxSE
a list containing the parameters method and
SE.factor used by maxSE to locate the gap
statistic optimum. The default is
list(method = "firstSEmax", SE.factor = 1). Allowed methods include:
"globalmax": simply corresponds to the global maximum,
i.e., is which.max(gap)
"firstmax": gives the location of the first
local maximum
"Tibs2001SEmax": uses the criterion, Tibshirani et al
(2001) proposed: "the smallest k such that gap(k) >= gap(k+1) - s(k+1)".
It's also possible to use "the smallest k such that gap(k) >= gap(k+1) -
SE.factor*s(k+1)" where SE.factor is a numeric value which can be 1
(default), 2, 3, etc.
"firstSEmax": location of the first f() value
which is not larger than the first local maximum minus SE.factor * SE.f,
i.e, within an "f S.E." range of that maximum.
see maxSE for more options