I am using package factoextra in R to generate a silhouette plot. Currently the silhouette automatically colours your graph via clustering. I want to color by another variable Site which I have defined as x. I have tried both fill and color changing it to the site variable but nothing seems to work. I have also tried using scale_color_manual and scale_fill_discrete. I think the key is in scale_fill_discrete as the source code from another user points out
mapping <- aes_string(x = "name", y = "sil_width", color = "cluster", fill = "cluster")
I basically need to change color="cluster" to colour= "x".
I have reverted the final plotting code back to its most basic form.
pamspec <- pam(spec, 3, keep.diss = TRUE)
plot(pamspec)
spec <- cbind(pamspec$clustering)
autoplot(pam(spec,3), frame=TRUE, frame.type = "norm")
pamspec$site <- spec$Site
x <- pamspec$site
fviz_silhouette(pamspec, label=TRUE) + theme_classic()
