[R] Graphics question: How to create a changing "smudge factor" for overlapping lines?

From: Tal Galili <tal.galili_at_gmail.com>
Date: Tue, 15 Jun 2010 13:57:57 +0300

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:

# ------------------------------------

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)
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)

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 ?


Contact me: Tal.Galili_at_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_at_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. Received on Tue 15 Jun 2010 - 11:00:21 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 16 Jun 2010 - 07:50:33 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive