plot.CARP provides a range of ways to visualize the results of convex clustering, including:

  • A dendrogram, illustrating the nested cluster hierarchy inferred from the convex clustering solution path (type = "dendrogram");

  • A static path plot, showing the coalescence of the estimated cluster centroids at a fixed value of the regularization parameter is increased (type = "path");

  • A gganimate plot, showing the coalescence of the estimated cluster centroids as the regularization parameter is increased (dynamic = TRUE)

# S3 method for CARP
plot(
  x,
  ...,
  type = c("dendrogram", "path", "heatmap"),
  dynamic = FALSE,
  interactive = FALSE,
  axis = c("PC1", "PC2"),
  percent,
  k,
  percent.seq = seq(0, 1, 0.01),
  slider_y = -0.3,
  refit = FALSE
)

Arguments

x

An object of class CARP as returned by CARP

...

Additional arguments, which are handled differently for different values of type.

  • When type is "path", the presence of unknown arguments triggers an error;

  • when type == "dendrogram" ... is forwarded to dendrogram; and

  • when type == "heatmap" and interactive == TRUE, ... is forwarded to heatmaply.

See the documentation of ggplot (for interactive == FALSE) or plotly (for interactive == TRUE) for details about additional supported arguments to the corresponding plot type.

type

A string indicating the type of visualization to show (see details above).

dynamic

A logical scalar.Should the resulting animation be dynamic (animated) or not? If TRUE, a dynamic visualization which varies along the CARP solution path at a grid given by percent.seq is produced. If FALSE, a fixed visualization at a single solution (determined by either percent or k if supplied) is produced.

interactive

A logical scalar. Should the resulting animation be interactive or not? If TRUE, an interactive visualization is produced by javascript(plotly). If FALSE, a non-interactive visualization is produced by ggplot.

axis

A character vector of length two indicating which features or principal components to use as the axes in the type = "path" visualization. Currently only features like "PC1" or "PC2" (indicating the first principal component projections) are supported.

percent

A number between 0 and 1, giving the regularization level (as a fraction of the final regularization level used) at which to assign clusters in the static (type = "dendrogram" or type = "path") plots.

k

An integer indicating the desired number of clusters to be displayed in the static plots. If no CARP iteration with exactly this many clusters is found, the first iterate with fewer than k clusters is used.

percent.seq

A grid of values of percent along which to generate dynamic visualizations (if dynamic == TRUE)

slider_y

A number to adjust the slider's vertical position for interactive dendrogram and interactive heatmap plots (ignored for other plot types).

refit

A logical scalar. Should "naive" centroids (TRUE) or the actual centroids estimated by convex clustering be used? When the default refit = FALSE, the estimated U from the convex clustering problem is used. The refit = TRUE returns actual centroids (mean) of all elements assigned to that cluster; Due to the global shrinkage imposed, these clusters are more "shrunk together" than the naive clusters. Only for the heatmap plots. (ignored for other plot types).

Value

The value of the return type depends on the interactive and dynamic arguments:

  • if interactive = FALSE and dynamic = FALSE, an object of class ggplot is returned;

  • if interactive = FALSE and dynamic = TRUE, an object of class gganim is returned;

  • if interactive = TRUE, an object of class plotly is returned.

All the plots can be plotted directly (by invoking its print method) or further manipulated by the user.

Examples

carp_fit <- CARP(presidential_speech)
#> Pre-computing weights and edge sets
#> Computing Convex Clustering [CARP] Path
#> Post-processing
plot(carp_fit, type = "path")
plot(carp_fit, type = "dendrogram")
plot(carp_fit, type = "heatmap")
plot(carp_fit, type = "heatmap", dynamic = TRUE) if (FALSE) { plot(carp_fit, type='heatmap', interactive=TRUE) }