Learn R Programming

sjPlot (version 1.7)

sjc.qclus: Compute quick cluster analysis

Description

Compute a quick kmeans or hierarchical cluster analysis and displays "cluster characteristics" as graph.
  1. Ifmethodiskmeans, this function first determines the optimal group count via gap statistics (unless parametergroupcountis specified), using thesjc.kgapfunction.
  2. A cluster analysis is performed by running thesjc.clusterfunction to determine the cluster groups.
  3. Then, all variables indataare scaled and centered. The mean value of these z-scores within each cluster group is calculated to see how certain characteristics (variables) in a cluster group differ in relation to other cluster groups.
  4. These results are plotted as graph.
This method can also be used to plot existing cluster solution as graph witouth computing a new cluster analysis. See parameter groups for more details.

Usage

sjc.qclus(data, groupcount = NULL, groups = NULL, method = "k",
  distance = "euclidean", agglomeration = "ward", iter.max = 20,
  algorithm = "Hartigan-Wong", showAccuracy = FALSE, title = NULL,
  axisLabels.x = NULL, axisTitle.x = "Cluster group characteristics",
  axisTitle.y = "Mean of z-scores", breakTitleAt = 40, breakLabelsAt = 20,
  breakLegendTitleAt = 20, breakLegendLabelsAt = 20, facetCluster = FALSE,
  geom.colors = "Paired", geom.size = 0.5, geom.spacing = 0.1,
  hideLegend = FALSE, showAxisLabels.x = TRUE, showAxisLabels.y = TRUE,
  showGroupCount = TRUE, showAccuracyLabels = FALSE, legendTitle = NULL,
  legendLabels = NULL, coord.flip = FALSE, reverseAxis.x = FALSE,
  printPlot = TRUE)

Arguments

Value

(Invisibly) returns an object with
  • data: the used data frame for plotting,
  • plot: the ggplot object,
  • groupcount: the number of found cluster (as calculated bysjc.kgap)
  • classification: the group classification (as calculated bysjc.cluster), including missing values, so this vector can be appended to the original data frame.
  • accuracy: the accuracy of group classification (as calculated bysjc.grpdisc).

References

Maechler M, Rousseeuw P, Struyf A, Hubert M, Hornik K (2014) cluster: Cluster Analysis Basics and Extensions. R package.

See Also

Examples

Run this code
# k-means clustering of mtcars-dataset
sjc.qclus(mtcars)

# k-means clustering of mtcars-dataset with 4 pre-defined
# groups in a faceted panel
sjc.qclus(airquality,
          groupcount = 4,
          facetCluster = TRUE)

# k-means clustering of airquality data
# and saving the results. most likely, 3 cluster
# groups have been found (see below).
airgrp <- sjc.qclus(airquality)

# "re-plot" cluster groups, without computing
# new k-means cluster analysis.
sjc.qclus(airquality,
          groupcount = 3,
          groups = airgrp$classification)

Run the code above in your browser using DataLab