| plot.mbcfit | R Documentation |
This function provides a plot method for objects of class mbcfit, returned as output by the gmix function. It serves as a wrapper around plot_clustering, allowing easy visualization of clustering results, including clustering assignments, contours, and boundaries.
## S3 method for class 'mbcfit'
plot(x, data = NULL, subset = NULL,
what = c("clustering", "contour"),
col_cl = NULL, pch_cl = NULL, ...)
x |
An object of class |
data |
|
subset |
A numeric vector indexing columns of |
what |
Character vector specifying which elements to plot. Options are |
col_cl |
A vector of colors to use for clusters (one for each cluster). Default is |
pch_cl |
A vector of plotting symbols (one for each cluster) to use for clusters. Default is |
... |
Further arguments passed to or from other methods. |
The plot.mbcfit function provides a plotting method for objects of the class mbcfit. It acts as a wrapper around the plot_clustering function, allowing users to easily generate various plots to analyze the clustering results. A plot is produced only upon a successful mbcfit estimate, i.e., when mbcfit has code equal to either 1 or 2.
When data is NULL (the default), the function plots only contour sets (and optionally clustering boundaries) for the estimated mixture density components, using the params information from the mbcfit object. When data is not NULL, the function additionally plots data points and their hard clustering labels, which are obtained using mbcfit to predict the cluster labels (see predict.mbcfit).
A plot displaying the data with clustering information, contours, and/or boundaries, depending on the specified what argument.
gmix, plot_clustering, link{predict.mbcfit}
# load data
data("banknote")
dat <- banknote[-1]
# fit 2 clusters
set.seed(123)
fit <- gmix(dat, K = 2, init.nstart = 1)
print(fit)
# plot partition (default)
plot(x = fit, data = dat)
# plot partition onto the first 3 coordinates
plot(x = fit, data = dat, subset = c(1:3), pch_cl = c("A", "B"),
col_cl = c("#4285F4", "#0F9D58"), what = "clustering")
# additionally plot clustering boundary and contour sets
plot(x = fit, data = dat, subset = c(1:3), pch_cl = c("A", "B"),
col_cl = c("#4285F4", "#0F9D58"), what = c("clustering", "boundary", "contour"))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.