Learn R Programming

flexclust (version 1.4-1)

barplot-methods: Barplot/chart Methods in Package `flexclust'

Description

Barplot of cluster centers or other cluster statistics.

Usage

# S4 method for kcca
barplot(height, bycluster = TRUE, oneplot = TRUE,
    data = NULL, FUN = colMeans, main = deparse(substitute(height)), 
    which = 1:height@k, names.arg = NULL,
    oma = par("oma"), col = NULL, mcol = "darkred", srt = 45, ...)

# S4 method for kcca barchart(x, data, xlab="", strip.labels=NULL, strip.prefix="Cluster ", col=NULL, mcol="darkred", mlcol=mcol, which=NULL, legend=FALSE, shade=FALSE, diff=NULL, byvar=FALSE, clusters=1:x@k, ...) # S4 method for hclust barchart(x, data, xlab="", strip.labels=NULL, strip.prefix="Cluster ", col=NULL, mcol="darkred", mlcol=mcol, which=NULL, shade=FALSE, diff=NULL, byvar=FALSE, k=2, ...) # S4 method for bclust barchart(x, data, xlab="", strip.labels=NULL, strip.prefix="Cluster ", col=NULL, mcol="darkred", mlcol=mcol, which=NULL, legend=FALSE, shade=FALSE, diff=NULL, byvar=FALSE, k=x@k, clusters=1:k, ...)

Arguments

height, x

An object of class "kcca".

bycluster

If TRUE, then each barplot shows one cluster. If FALSE, then each barplot compares all cluster for one input variable.

oneplot

If TRUE, all barplots are plotted together on one page, else each plot is on a separate page.

data

If not NULL, cluster membership is predicted for the new data and used for the plots. By default the values from the training data are used. Ignored by the barchart method.

FUN

The function to be applied to each cluster for calculating the bar heights. Only used, if data is not NULL.

which

For barplot index number of clusters for the plot, for barchart index numbers or names of variables to plot.

names.arg

A vector of names to be plotted below each bar.

main, oma, xlab, …

Graphical parameters.

col

Vector of colors for the clusters.

mcol,mlcol

If not NULL, the value of FUN for the complete data set is plotted over each bar as a point with color mcol and a line segment starting in zero with color mlcol.

srt

Number between 0 and 90, rotation of the x-axis labels.

strip.labels

Vector of strings for the strips of the Trellis display.

strip.prefix

Prefix string for the strips of the Trellis display.

legend

If TRUE, the barchart is always plotted on the current graphics device and a legend is added to the bottom of the plot.

shade

If TRUE, only bars with large absolute or relative deviation deviation from the sample mean of the respective variables are plotted in color.

diff

A numerical vector of length two with absolute and relative deviations for shading, default is \(max/4\) absolute deviation and 50% relative deviation.

byvar

If TRUE, a panel is plotted for each variable. By default a panel is plotted for each cluster.

clusters

Integer vector of clusters to plot.

k

Integer specifying the desired number of clusters.

References

Sara Dolnicar and Friedrich Leisch. Using graphical statistics to better understand market segmentation solutions. International Journal of Market Research, 56(2), 97-120, 2014.

Examples

Run this code
# NOT RUN {
  cl <- cclust(iris[,-5], k=3)
  barplot(cl)
  barplot(cl, bycluster=FALSE)

  ## plot the maximum instead of mean value per cluster:
  barplot(cl, bycluster=FALSE, data=iris[,-5],
          FUN=function(x) apply(x,2,max))

  ## use lattice for plotting:
  barchart(cl)
  ## automatic abbreviation of labels
  barchart(cl, scales=list(abbreviate=TRUE))
  ## origin of bars at zero
  barchart(cl, scales=list(abbreviate=TRUE), origin=0)

  ## Use manual labels. Note that the flexclust barchart orders bars
  ## from top to bottom (the default does it the other way round), hence
  ## we have to rev() the labels:
  LAB <- c("SL", "SW", "PL", "PW")
  barchart(cl, scales=list(y=list(labels=rev(LAB))), origin=0)

  ## deviation of each cluster center from the population means
  barchart(cl, origin=rev(cl@xcent), mlcol=NULL)

  ## use shading to highlight large deviations from population mean
  barchart(cl, shade=TRUE)

  ## use smaller deviation limit than default and add a legend
  barchart(cl, shade=TRUE, diff=0.2, legend=TRUE)
# }

Run the code above in your browser using DataLab