I'm trying to (partially) reproduce the cluster plot available throught s.class(...)
in package ade4
using ggplot
, but this question is actually much more general.
NB: This question refers to "star plots", but really only discusses spider plots.
df <- mtcars[,c(1,3,4,5,6,7)]
pca <-prcomp(df, scale.=T, retx=T)
scores <-data.frame(pca$x)
library(ade4)
km <- kmeans(df,centers=3)
plot.df <- cbind(scores$PC1, scores$PC2)
s.class(plot.df, factor(km$cluster))
The essential feature I'm looking for is the "stars", e.g. a set of lines radiating from a common point (here, the cluster centroids) to a number of other points (here, the points in the cluster).
Is there a way to do that using the ggplot
package? If not directly through ggplot
, then does anyone know of an add-in that works. For example, there are several variations on stat_ellipse(...)
which is not part of the ggplot
package (here, and here).