View source: R/plot_clustering.R
plot_clustering | R Documentation |
This function plots data and optionally adds clustering information such as clustering assignments, contours, or boundaries.
plot_clustering(data, subset = NULL,
cluster = NULL, params = NULL,
what = c("clustering", "contour", "boundary"),
col_cl = NULL, pch_cl = NULL)
data |
a numeric vector, matrix, or data frame of observations. Rows correspond to observations and columns correspond to variables/features. Categorical variables and |
subset |
A numeric vector indexing columns of |
cluster |
A vector of cluster assignments. If provided, the plot can display clustering information as specified in |
params |
A list of clustering parameters, including |
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 |
No return value, called for side effects
bqs
, clust2params
# Example data
set.seed(123)
data <- rbind(
matrix(rnorm(100 * 2), ncol = 2),
matrix(rnorm(100 * 2) + 2, ncol = 2)
)
cluster <- c(rep(1, 100), rep(2, 100))
params <- clust2params(data, cluster)
# Plot with clustering information
plot_clustering(data, cluster = cluster, what = "clustering")
# Plot with subset of variables
plot_clustering(data, cluster = cluster, subset = 1, what = c("clustering", "contour"))
# Plot with customized colors and symbols
plot_clustering(data, cluster = cluster, params = params,
col_cl = c("magenta", "orange"), pch_cl = c("A", "B"))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.