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

Description Usage Arguments Note Author(s) References Examples

Description

Barplot of cluster centers or other cluster statistics.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
## S4 method for signature '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 signature '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 signature '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 signature '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.

Note

The flexclust barchart method uses a horizontal arrangements of the bars, and sorts them from top to bottom. Default barcharts in lattice are the other way round (bottom to top). See the examples below how this affects, e.g., manual labels for the y axis.

The barplot method is legacy code and only maintained to keep up with changes in R, all active development is done on barchart.

Author(s)

Friedrich Leisch

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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
  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)

Example output

Loading required package: grid
Loading required package: lattice
Loading required package: modeltools
Loading required package: stats4
NULL

flexclust documentation built on May 2, 2019, 10:59 a.m.