Learn R Programming

flexclust (version 1.3-4)

stripes: Stripes Plot

Description

Plot distance of data points to cluster centroids using stripes.

Usage

stripes(object, groups=NULL, type=c("first", "second", "all"), beside=(type!="first"), col=NULL, gp.line=NULL, gp.bar=NULL, gp.bar2=NULL, number=TRUE, legend=!is.null(groups), ylim=NULL, ylab="distance from centroid", margins=c(2,5,3,2), ...)

Arguments

object
an object of class "kcca".
groups
grouping variable to color-code the stripes. By default cluster membership is used as groups.
type
plot distance to closest, closest and second-closest or to all centroids?
beside
logical, make different stripes for different clusters?
col
vector of colors for clusters or groups.
gp.line, gp.bar, gp.bar2
graphical parameters for horizontal lines and background rectangular areas, see gpar.
number
logical, write cluster numbers on x-axis?
legend
logical, plot a legend for the groups?
ylim, ylab
graphical parameters for y-axis.
margins
margin of the plot.
...
further graphical parameters.

Details

A simple, yet very effective plot for visualizing the distance of each point from its closest and second-closest cluster centroids is a stripes plot. For each of the k clusters we have a rectangular area, which we optionally vertically divide into k smaller rectangles (beside=TRUE). Then we draw a horizontal line segment for each data point marking the distance of the data point from the corresponding centroid.

References

Friedrich Leisch. Neighborhood graphs, stripes and shadow plots for cluster visualization. Statistics and Computing, 2009. Accepted for publication on 2009-06-16.

Examples

Run this code
bw05 <- bundestag(2005)
bavaria <- bundestag(2005, state="Bayern")

set.seed(1)
c4 <- cclust(bw05, k=4, save.data=TRUE)
plot(c4)

stripes(c4)
stripes(c4, beside=TRUE)

stripes(c4, type="sec")
stripes(c4, type="sec", beside=FALSE)
stripes(c4, type="all")

stripes(c4, groups=bavaria)

## ugly, but shows how colors of all parts can be changed
library("grid")
stripes(c4, type="all",
        gp.bar=gpar(col="red", lwd=3, fill="white"),
        gp.bar2=gpar(col="green", lwd=3, fill="black"))

Run the code above in your browser using DataLab