Error in UseMethod ("depth") when visualizing cluster using fviz_cluster

Hi everyone, I am very much a newbie in using RStudio and I am using it for my research study.
I am having problem in visualizing the clusters generated by KMeans method. The data I am using is Uber pickup data in year 2014.

FYI, I am following the code used by this link.

The only difference is that I am using fviz_cluster to visualize the clusters but I keep getting error as shown below.

Error in UseMethod("depth") :
no applicable method for 'depth' applied to an object of class "NULL"
traceback()
12: depth(path)
11: upViewport(depth(vp), recording = FALSE)
10: popgrobvp.viewport(x$vp)
9: popgrobvp(x$vp)
8: postDraw.grob(x)
7: postDraw(x)
6: drawGTree(x)
5: recordGraphics(drawGTree(x), list(x = x), getNamespace("grid"))
4: grid.draw.gTree(gtable)
3: grid.draw(gtable)
2: print.ggplot(x)
1: (function (x, ...)
UseMethod("print"))(x)

Any idea why this happens and how to resolve it?

Below are the codes that I used for kmeans method and fviz_cluster

Create cluster using kmeans

set.seed(123) # to create a starting point for randomly generated numbers
clusters <- kmeans(data14[,2:3], 5)
str(clusters)
data14_latlong <- data14[,2:3] # getting lat and long from data
library(factoextra)
fviz_cluster(clusters, data = data14_latlong,
repel = TRUE,
star.plot = TRUE,
geom = "point",
ellipse.type = "euclid",
ggtheme = theme_minimal()
)

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.