plot.mbcfit: Plot Fitted Mixture Models

View source: R/plot_mbcfit.R

plot.mbcfitR Documentation

Plot Fitted Mixture Models

Description

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.

Usage

## S3 method for class 'mbcfit'
plot(
  x,
  data = NULL,
  subset = NULL,
  what = c("clustering", "contour"),
  col_cl = NULL,
  pch_cl = NULL,
  ...
)

Arguments

x

An object of class mbcfit, typically a result of the gmix function.

data

NULL or a data matrix, data frame, or array containing data points to be plotted. When supplied, it is typically the data set used to fit x. See Details.

subset

A numeric vector indexing columns of data to subset and focus the plot on specific features. Default is NULL.

what

Character vector specifying which elements to plot. Options are "clustering", "contour", and "boundary". Default is to plot "clustering" and "contour". Unavailable plot features are ignored or rejected downstream by plot_clustering depending on the inputs. See Details.

col_cl

A vector of colors to use for clusters (one for each cluster). Default is NULL, which uses a default sequence of colors.

pch_cl

A vector of plotting symbols (one for each cluster) to use for clusters. Default is NULL, which uses a default sequence of symbols.

...

Further arguments passed to or from other methods.

Details

The plot.mbcfit function provides a plotting method for objects of 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. The plot features that can actually be drawn depend on the components stored in x, in particular x$params and x$cluster.

When data is NULL (the default), the function constructs a synthetic plotting data set from the fitted params and then delegates the plotting to plot_clustering.

When data is not NULL, the function passes data, the stored mixture parameters, and the hard clustering labels saved in x$cluster to plot_clustering.

Value

Called for its side effects.

See Also

gmix, plot_clustering, predict.mbcfit

Examples

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



qcluster documentation built on June 5, 2026, 5:07 p.m.