Learn R Programming

sjPlot (version 2.0.0)

sjc.qclus: Compute quick cluster analysis

Description

Compute a quick kmeans or hierarchical cluster analysis and displays "cluster characteristics" as plot.

Usage

sjc.qclus(data, groupcount = NULL, groups = NULL, method = c("kmeans",
  "hclust"), distance = c("euclidean", "maximum", "manhattan", "canberra",
  "binary", "minkowski"), agglomeration = c("ward", "ward.D", "ward.D2",
  "single", "complete", "average", "mcquitty", "median", "centroid"),
  iter.max = 20, algorithm = c("Hartigan-Wong", "Lloyd", "MacQueen"),
  show.accuracy = FALSE, title = NULL, axis.labels = NULL,
  wrap.title = 40, wrap.labels = 20, wrap.legend.title = 20,
  wrap.legend.labels = 20, facet.grid = FALSE, geom.colors = "Paired",
  geom.size = 0.5, geom.spacing = 0.1, show.legend = TRUE,
  show.grpcnt = TRUE, legend.title = NULL, legend.labels = NULL,
  coord.flip = FALSE, reverse.axis = FALSE, prnt.plot = 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).

Details

Following steps are computed in this function:
  1. Ifmethod = "kmeans", this function first determines the optimal group count via gap statistics (unless argumentgroupcountis 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 argument groups for more details.

References

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

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, facet.grid = 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