Learn R Programming

MSmix (version 1.0.2)

plot.dist: Plot the Spearman distance matrix

Description

plot method for class "dist". It is useful to preliminary explore the presence of patterns (groups) of similar preferences in the ranking dataset.

Usage

# S3 method for dist
plot(
  x,
  order = TRUE,
  show_labels = TRUE,
  lab_size = 3,
  gradient = list(low = "#00AFBB", mid = "white", high = "#FC4E07"),
  ...
)

Value

Produce a heatmap of the Spearman distance matrix between all pairs of full rankings.

Arguments

x

An object of class "dist", returned by spear_dist when setting the argument rho = NULL.

order

Logical: whether the rows of the distance matrix must be ordered. Defaults to TRUE.

show_labels

Logical: whether the labels must be displayed on the axes. Defaults to TRUE.

lab_size

Positive scalar: the magnification of the labels on the axes. Defaults to 3.

gradient

List of three elements with the colors for low, mid and high values of the distances in the heatmap. The element mid can take the value of NULL.

...

Further arguments passed to or from other methods (not used).

Details

plot.dist can visualize a distance matrix of any metric, provided that its class is "dist". It can take a few seconds if the size of the distance matrix is large.

The heatmap can be also obtained by setting the arguments rho = NULL and plot_dist_mat = TRUE when applying spear_dist.

References

Alboukadel K and Mundt F (2020). factoextra: Extract and Visualize the Results of Multivariate Data Analyses. R package version 1.0.7. https://CRAN.R-project.org/package=factoextra

See Also

spear_dist

Examples

Run this code

## Example 1. Plot the Spearman distance matrix of the Antifragility ranking dataset.
r_antifrag <- ranks_antifragility[, 1:7]
dist_mat <- spear_dist(rankings = r_antifrag)
plot(dist_mat, show_labels = FALSE)

## Example 2. Plot the Spearman distance matrix of the Sports ranking dataset.
r_sports <- ranks_sports[, 1:8]
dist_mat <- spear_dist(rankings = r_sports)
plot(dist_mat, show_labels = FALSE)
# Plot the Spearman distance matrix for the subsample of males.
dist_m <- spear_dist(rankings = r_sports, subset = (ranks_sports$Gender == "Male"))
plot(dist_m)


Run the code above in your browser using DataLab