barplot-methods {flexclust} | R Documentation |
Barplot/chart Methods in Package ‘flexclust’
Description
Barplot of cluster centers or other cluster statistics.
Usage
## 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 |
bycluster |
If |
oneplot |
If |
data |
If not |
FUN |
The function to be applied to each cluster for calculating
the bar heights. Only used, if |
which |
For |
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 |
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 |
shade |
If |
diff |
A numerical vector of length two with absolute and
relative deviations for shading, default is |
byvar |
If |
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
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)