Learn R Programming

useful (version 1.2.0)

plot.kmeans: plot.kmeans

Description

Plot the results from a k-means object

Usage

## S3 method for class 'kmeans':
plot(x, data = NULL, class = NULL,
  legend.position = c("right", "bottom", "left", "top", "none"),
  title = "K-Means Results", xlab = "Principal Component 1",
  ylab = "Principal Component 2", ...)

Arguments

x
A kmeans object.
data
The data used to kit the kmeans object.
class
Character name of the "true" classes of the data.
legend.position
Character indicating where the legend should be placed.
title
Title for the plot.
xlab
Label for the x-axis.
ylab
Label for the y-axis.
...
Not Used.

Value

  • A ggplot object

Details

Plots the results of k-means with color-coding for the cluster membership. If data is not provided, then just the center points are calculated.

See Also

kmeans fortify ggplot plot.kmeans

Examples

Run this code
k1 <- kmeans(x=iris[, 1:4], centers=3)
plot(k1)
plot(k1, data=iris)

Run the code above in your browser using DataLab