autoplot.LearnerClustHierarchical: Plot for Hierarchical Clustering Learners

View source: R/LearnerClustHierarchical.R

autoplot.LearnerClustHierarchicalR Documentation

Plot for Hierarchical Clustering Learners

Description

Generates plots for hierarchical clusterers, depending on argument type:

  • "dend" (default): dendrograms using factoextra package.

  • "scree": scree plot that shows the number of possible clusters on x-axis and the height on the y-axis.

Note that learner-specific plots are experimental and subject to change.

Usage

## S3 method for class 'LearnerClustHierarchical'
autoplot(object, type = "dend", ...)

Arguments

object

(mlr3cluster::LearnerClustAgnes | mlr3cluster::LearnerClustDiana | mlr3cluster::LearnerClustHclust).

type

(character(1)):
Type of the plot. See description.

...

(any): Additional arguments, passed down to function factoextra::fviz_dend() in package factoextra.

Value

ggplot2::ggplot() object.

Theme

The theme_mlr3() and viridis color maps are applied by default to all autoplot() methods. To change this behavior set options(mlr3.theme = FALSE).

Examples

if (requireNamespace("mlr3")) {
  library(mlr3)
  library(mlr3cluster)
  library(mlr3viz)

  task = mlr_tasks$get("usarrests")

  # agnes clustering
  learner = mlr_learners$get("clust.agnes")
  learner$train(task)
  autoplot(learner)

  # diana clustering
  learner = mlr_learners$get("clust.diana")
  learner$train(task)
  autoplot(learner,
    k = learner$param_set$values$k, rect_fill = TRUE,
    rect = TRUE, rect_border = "red")

  # hclust clustering
  learner = mlr_learners$get("clust.hclust")
  learner$train(task)
  autoplot(learner, type = "scree")
}

mlr3viz documentation built on Aug. 15, 2022, 5:07 p.m.