plot.kMeans: Plot the results of k-means clustering

Description Usage Arguments Required Examples

View source: R/plot.R

Description

plot method for class "kMeans". The result is a 2D-scatterplot containing the data points and the centroids coloured by their cluster allocation. If the dimension is higher than two, the user is asked to provide the names of the two variables that should be plotted.

Usage

1
2
## S3 method for class 'kMeans'
plot(x, ...)

Arguments

x

an object of class "kMeans".

...

further arguments passed to or from other methods.

Required

ggplot2

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
# create example data set
X <- rbind(matrix(rnorm(50, sd = 0.5), ncol = 2),
matrix(rnorm(50, mean = 1, sd = 0.5), ncol = 2))

# perform k-means algorithm
result <- kMeansLloyd(x = X, centroids = 2, nStart = 2)

# plot result
library(ggplot2)
plot(result)

heiligerl/kMeans_Rpackage documentation built on Aug. 16, 2020, 4:04 p.m.