Given a clustering over a dataset with N variables:
data(iris)
df <- iris[,1:4]
fit <- kmeans(df, 3)
I would like to visualise the results using whisker plots, where:
- x-axis corresponds to variables or dimensions.
- boxes indicate the cluster mean (horizontal line) and the variance of the group.
- For every x value (variable) there are
k
boxes, one per group. - Data points are also shown.
I get to this:
points <- df
points$cluster <- fit$cluster
points <- melt(points, id='cluster')
p <- ggplot(points, aes(x=variable, y=value))
p <- p + geom_boxplot(aes(fill = factor(cluster)))
p <- p + geom_jitter(aes(color=factor(cluster)))
print(p)
But the jitter points should be aligned in with their corresponding boxes. How can I do it?