The dashed line is an expected behaviour of fviz_silhoutte
; it's the visualization of a summary statistic, rather than a stray grid line.
It's lightly hacky, but you can edit the parameters of the plot object to make the line disappear. Setting aes_params$colour
to NA
will render it invisible.
library(factoextra)
library(cluster)
set.seed(123)
data("iris")
iris.scaled <- scale(iris[, -5])
# K-means clustering
km.res <- kmeans(iris.scaled, 3, nstart = 2)
# Visualize silhouhette information
sil <- silhouette(km.res$cluster, dist(iris.scaled))
viz_sil <- fviz_silhouette(sil) +
scale_color_manual('', values = c("#008B4544", "#FF000033", "#1C86EE44"), aesthetics = c("color", "fill"))
#> cluster size ave.sil.width
#> 1 1 50 0.64
#> 2 2 53 0.39
#> 3 3 47 0.35
viz_sil$layers[[2]]$aes_params$colour <- NA
viz_sil
Created on 2021-01-25 by the reprex package (v0.3.0)
Solution based off of this answer.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…