-
- ### Mean in each cluster
- XY <- cbind(X, Y)
- XY_class <- list()
- meanPerClass <- matrix(0, ncol = K, nrow = dim(XY)[2])
- for (r in 1:K)
- {
- XY_class[[r]] <- XY[model$affec == r, ]
- if (sum(model$affec == r) == 1) {
- meanPerClass[, r] <- XY_class[[r]]
- } else {
- meanPerClass[, r] <- apply(XY_class[[r]], 2, mean)
- }
- }
- data <- data.frame(mean = as.vector(meanPerClass),
- cluster = as.character(rep(1:K, each = dim(XY)[2])), time = rep(1:dim(XY)[2], K))
- g <- ggplot(data, aes(x = "time", y = "mean", group = "cluster", color = "cluster"))
- print(g + geom_line(aes(linetype = "cluster", color = "cluster"))
- + geom_point(aes(color = "cluster")) + ggtitle("Mean per cluster"))