0

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)

enter image description here

But the jitter points should be aligned in with their corresponding boxes. How can I do it?

alberto
  • 2,625
  • 4
  • 29
  • 48
  • About the jittered points see this [question and answer](http://stackoverflow.com/questions/10493084/ggplot2-jitter-and-position-dodge-together). Is the position of points your only problem? – Didzis Elferts Jan 21 '16 at 14:57
  • Yes, the position is my only problem now (thanks, I'm looking into your link) – alberto Jan 21 '16 at 15:00

0 Answers0