plotColoredClusters {ClassDiscovery} | R Documentation |
Provides an interface to plclust
that makes it easier to
plot dendrograms with labels that are color-coded, usually to indicate
the different levels of a factor.
plotColoredClusters(hd, labs, cols, cex = 0.8, main = "", line = 0, ...)
hd |
An object with S3 class hclust , as produced bny the
hclust function. |
labs |
A vector of character strings used to label the leaves inth e dendrogram |
cols |
A vector of color names suitable for passing to the
col argument of graphics routines. |
cex |
A numeric value; the character expansion parameter of
par . |
main |
A character string; the plot title |
line |
An integer determining how far away to plot the labels;
see mtext for details. |
... |
Any additional graphical parameters that can be supplied
when plotting an hclust object. |
This function is used to implement the pltree
methods of the
Mosaic
class and the PCanova
class. It simply bundles
a two step process (first plotting the dendrogram with no labels,
followed by writing the labels in the right places with the desired
colors) into a single unit.
The function has no useful return value; it merely produces a plot.
plclust
, hclust
,
Mosaic
, PCanova
, par
# simulate data from three different groups d1 <- matrix(rnorm(100*10, rnorm(100, 0.5)), nrow=100, ncol=10, byrow=FALSE) d2 <- matrix(rnorm(100*10, rnorm(100, 0.5)), nrow=100, ncol=10, byrow=FALSE) d3 <- matrix(rnorm(100*10, rnorm(100, 0.5)), nrow=100, ncol=10, byrow=FALSE) dd <- cbind(d1, d2, d3) # perform hierarchical clustering using correlation hc <- hclust(distanceMatrix(dd, 'pearson'), method='average') cols <- rep(c('red', 'green', 'blue'), each=10) labs <- paste('X', 1:30, sep='') # plot the dendrogram with color-coded groups plotColoredClusters(hc, labs=labs, cols=cols) #cleanup rm(d1, d2, d3, dd, hc, cols, labs)