factoextra icon indicating copy to clipboard operation
factoextra copied to clipboard

fviz_cluster & pam: dissimiliarty matrix issues

Open datasci-iopsy opened this issue 4 years ago • 2 comments

Hello,

Thank you for all of your work on this package - it makes unsupervised learning fun to implement and visualise!

I am currently having issues getting the fviz_cluster() function to properly graph the output from a "pam" object. A quick overview of the code:

library(factorextra)
library(cluster)

## pseudo data
data -> df 

## calculate distance measure - correlation based
get_dist(df, method = "spearman") -> dist_mtx

## compute analysis w/ 4 clusters
cluster::pam(x = dist_mtx, k = 4, diss = TRUE) -> pam_res

## visualise results
fviz_cluster(x = pam_res, geom = "point")

I receive an error stating, "Error in array(x, c(length(x), 1L), if (!is.null(names))) list(names(x), : 'data' must be of vector type, was NULL"

Some people online have opted to append the original data to the "pam" results (i.e., df -> pam_res$data) to force a visual but I am wondering if there is a deeper issue with this fix. For instance, will appending the data is my dissimilarity matrix being ignored and the function is only using the original data - which would defeat the purpose.

datasci-iopsy avatar Jan 28 '21 20:01 datasci-iopsy

+1

paullemmens avatar Feb 10 '21 09:02 paullemmens

I am also receiving this error with the output of a fanny object from the cluster package

sarahsmithtripp avatar Apr 19 '23 20:04 sarahsmithtripp