[R] kmeans and plot labels

Sarah Goslee sarah.goslee at gmail.com
Fri Dec 16 15:29:42 CET 2011


You include no context, and I only vaguely remember your original
question. You also don't include a reproducible example.

But perhaps this helps?

testmat <- data.frame(x=c(1,1,2,3), y=c(2,1,3,2), names=letters[1:4],
with(testmat, plot(x, y, pch=names))


with(testmat, plot(x, y, type="n"))
with(testmat, text(x, y, names))

Otherwise you'll have to actually follow the posting guide and
pose a fully self-contained question.


On Fri, Dec 16, 2011 at 4:25 AM, Meesters, Christian <meesters at aesku.com> wrote:
> Hi,
> Thanks Sarah. Unfortunately I did not get a step further.
> My question, perhaps a bit clearer, is how to display the case control status (or any other arbitrary point label) after clustering in a plot:
> With a bit of pseudo code, where dataset is a data.frame, parameters are those column names where we find numerical values (no NAs) and nclasses is the desired number of classes.
> fit <- kmeans(dataset[, parameters], nclasses)
> plot(dataset[, parameters], col = fit$cluster, dimen = nclasses)
> This gives us a nicely coloured plot where all points are circled. Yet, my desire is to see the case / control-Status encoded in a column "Status" with single characters, in place of those circled points.
> Any hints? I did not get pch() nor text() to work. Perhaps the solution lies there, but them I am sure that I do not see the wood for all those trees ...
> Christian

Sarah Goslee

More information about the R-help mailing list