Learn R Programming

apcluster (version 1.2.1)

plot-methods: Plot Clustering Results

Description

Functions for Visualizing Clustering Results

Usage

## S3 method for class 'APResult,missing':
plot(x,
             type=c("netsim", "dpsim", "expref"),
             xlab="# Iterations",
             ylab="Similarity", ...)
## S3 method for class 'APResult,matrix':
plot(x, y,
              connect=TRUE, xlab="", ylab="", ...)
## S3 method for class 'ExClust,matrix':
plot(x, y,
              connect=TRUE, xlab="", ylab="", ...)
## S3 method for class 'AggExResult,missing':
plot(x, main="Cluster dendrogram",
              xlab="", ylab="Balanced avg. similarity to exemplar",
              ticks=4, digits=2, ...)
## S3 method for class 'AggExResult,matrix':
plot(x, y, k=NA, h=NA, ...)

Arguments

x
a clustering result object of class APResult, ExClust, or AggExResult
y
a matrix (see details below)
type
a string or array of strings indicating which performance measures should be plotted; valid values are "netsim", "dpsim", and "expref" which can be used in any combination or
xlab
label for x axis of plot
ylab
label for y axis of plot
connect
used only if clustering is plotted on original data, ignored otherwise. If connect is TRUE, lines are drawn connecting exemplars with their cluster members.
main
title of plot
ticks
number of ticks used for the axis on the left side of the plot (applies to dendrogram plots only, see below)
digits
number of digits used for the axis tickmarks on the left side of the plot (applies to dendrogram plots only, see below)
k
level to be selected when plotting a single clustering level of cluster hierarchy (i.e. the number of clusters; see cutree-methods)
h
cut-off to be used when plotting a single clustering level of cluster hierarchy (see cutree-methods)
...
all other arguments are passed to the plotting command that are used internally, plot or heatmap.

Value

  • see details above

code

ExClust

Details

If plot is called for an APResult object without specifying the second argument y, a plot is created that displays graphs of performance measures over execution time of the affinity propagation run. This only works if apcluster was called with details=TRUE, otherwise an error message is displayed. This variant of plot does not return any value.

If plot is called for an APResult object along with a matrix as argument y, then the dimensions of the matrix determine the behavior of plot:

  1. If the matrixyhas two columns,yis interpreted as the original data set. Then a plot of the clustering result superimposed on the original data set is created. Each cluster is displayed in a different color. The exemplar of each cluster is highlighted by a black square. IfconnectisTRUE, lines connecting the cluster members to their exemplars are drawn. This variant ofplotdoes not return any value.
If the matrix y is quadratic, y is interpreted as the similarity matrix that was used for clustering. Then a heatmap of the similarity matrix is drawn, where the clusters are grouped together and highlighted in different colors. The order of clusters is determined by running aggExCluster on the clustering result x. This variant of plot returns an invisible AggExResult object.

References

http://www.bioinf.jku.at/software/apcluster

Bodenhofer, U., Kothmeier, A., and Hochreiter, S. (2011) APCluster: an R package for affinity propagation clustering. Bioinformatics 27, 2463-2464. DOI: http://dx.doi.org/10.1093/bioinformatics/btr406{10.1093/bioinformatics/btr406}.

Frey, B. J. and Dueck, D. (2007) Clustering by passing messages between data points. Science 315, 972-976. DOI: http://dx.doi.org/10.1126/science.1136800{10.1126/science.1136800}.

See Also

APResult, AggExResult, ExClust, apcluster, aggExCluster, cutree-methods

Examples

Run this code
## create two Gaussian clouds
cl1 <- cbind(rnorm(50,0.2,0.05),rnorm(50,0.8,0.06))
cl2 <- cbind(rnorm(50,0.7,0.08),rnorm(50,0.3,0.05))
x <- rbind(cl1,cl2)

## compute similarity matrix (negative squared Euclidean)
sim <- negDistMat(x, r=2)

## run affinity propagation
apres <- apcluster(sim, q=0.6, details=TRUE)

## plot information about clustering run
plot(apres)

## plot clustering result
plot(apres, x)

## plot heatmap
plot(apres, sim)

## perform agglomerative clustering of affinity propagation clusters
aggres1 <- aggExCluster(sim, apres)

## show dendrogram
plot(aggres1)

## show heatmap
plot(aggres1, sim)

## show clustering result for 4 clusters
plot(aggres1, x, k=4)

## perform agglomerative clustering of whole data set
aggres2 <- aggExCluster(sim)

## show dendrogram
plot(aggres2)

## show heatmap along with dendrogram
plot(aggres2, sim)

## show clustering result for 2 clusters
plot(aggres2, x, k=2)

Run the code above in your browser using DataLab