Hello all, I am trying to create a Clustergram in R. (More about it here: http://www.schonlau.net/clustergram.html)
And to produce a picture similar to what is seen here: http://www.schonlau.net/images/clustergramexample.gif I was able (more or less) to write the R code for creating the image, but there is one thing I can't seem to figure out, that is the *changing*"smudge factor" of the lines. I want the overlapping lines to "jitter" a tiny bit so they will give a sense of thickness to the line (according to how many observations are present in that cluster). My current solution is to use a constant jitter (based on "seq") on all the k number of clusters, but that causes glitches in the produced image (run my code to see). Here is a simple self reproducible code to create the image I was able to make: # ------------------------------------ set.seed(100) Data <- rbind(matrix(rnorm(100, sd = 0.3), ncol = 2), matrix(rnorm(100, mean = 1, sd = 0.3), ncol = 2)) colnames(x) <- c("x", "y") # noise <- runif(100,0,.05) noise <- seq(0,.3, length.out = 100) Y <- NULL X <- NULL k.range <- 2:10 for(k in k.range) { cl <- kmeans(Data, k) y <- apply(cl$centers,1, mean)[cl$cluster] + noise Y <- cbind(Y, y) x <- rep(k, length(y)) X <- cbind(X, x) points(y ~ x) } require(colorspace) COL <- rainbow_hcl(100) plot(0,0, col = "white", xlim = c(1,10), ylim = c(-.5,1.6), xlab = "Number of clusters", ylab = "Clusters means", main = "(Basic) Clustergram") axis(side =1, at = k.range) abline(v = k.range, col = "grey") matlines(t(X), t(Y), pch = 19, col = COL, lty = 1, lwd = 1.5) # The next step would be to create a method for different cluster objects, but thats for another day... #-------------------------------------------- Any suggestions on how to do this ? Thanks, Tal ----------------Contact Details:------------------------------------------------------- Contact me: tal.gal...@gmail.com | 972-52-7275845 Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) | www.r-statistics.com (English) ---------------------------------------------------------------------------------------------- [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.