I am trying to run the function fviz_nbclust inside a function but it does not plot the graphic.
If I run in Debbug mode and press F10 on the fviz_nbclust line, it does not generate the graphic. But if I put the cursor on this line and press Ctrl+Enter, the graphic shows up.
Any clues?
Main code:
library(factoextra)
df <- cbind(rnorm(100, mean = 0, sd = 1),rnorm(100, mean = 0, sd = 1))
df
run_cluster(df)
Function code:
run_cluster <- function(df){
fviz_nbclust(df,
FUNcluster = kmeans,
method = "wss",
k.max = nrow(unique(df)) - 1,
nstart = 2)
return (T)
}
