Search code examples
rcolorssymbolspam

How to change the symbol and colour using fviz_cluster in R project


I am using R to make the cluster graph. My code as followed:

cluster<- fviz_cluster(final, data = y, labelsize = 1, ellipse.type = "convex", 
              ellipse.alpha = 0 ) 

cluster +   theme(axis.line = element_line(),
         panel.grid.major = element_blank(),
         panel.grid.minor = element_blank(),
         panel.border = element_blank(),
         panel.background = element_blank())

And this is my result after deleting all background colors. So I have a question that, how I can change the symbol of cluster 1 from oval to plus?


Solution

  • You can use the following code

    library(factoextra)
    
    data("iris")
    head(iris)
    # Remove species column (5) and scale the data
    iris.scaled <- scale(iris[, -5])
    
    # K-means clustering
    km.res <- kmeans(iris.scaled, 3, nstart = 10)
    
    # Visualize clustering
    cluster <- fviz_cluster(km.res, data = iris[, -5], labelsize = 1, 
                            ellipse.type = "convex", 
                            ellipse.alpha = 0) +
      scale_shape_manual(values=c(3,17,19)) 
    
    cluster + theme(axis.line = element_line(),
                      panel.grid.major = element_blank(),
                      panel.grid.minor = element_blank(),
                      panel.border = element_blank(),
                      panel.background = element_blank())
    

    enter image description here