[BioC] labeling a hclust tree with custom labels

Mikhail, Amy a.mikhail at abdn.ac.uk
Sat Mar 29 14:56:52 CET 2008

P.s. - forgot to mention that the below should be done before you create
your dist object - then the new sample names will automatically appear
in the right place on the hclust dendrogram.  Also, appologies - I have
always just typed my new sample names but just tried using a vector of
names instead and can't get this to work (the argument expects strings).
I am sure there should be an easy way to do this though...

Best wishes,

-----Original Message-----
From: Mikhail, Amy 
Sent: 29 March 2008 12:40
To: bioconductor at stat.math.ethz.ch
Cc: 'iaingallagher at btopenworld.com'; 'sdavis2 at mail.nih.gov'
Subject: Re: [BioC] labeling a hclust tree with custom labels

Hi Iain,

I'm guessing that the labels currently coming up on hclust are the names
of your .cel files?  If your expressionset is called my.expressionset,
and your desired sample names for images are "Control 1" etc, you could
just do:

sampleNames(my.expressionset) <- c("Control 1", "Control 2", "Control
3", "Treatment 1", "Treatment 2", "Treatment 3")

Nb1. You would have to follow the same order for the new sample names as
the order of columns in your expressionset.  If you have a lot of files
and already have a vector of your preferred sample names (in the right
order) you could just put that in instead of the list above and it would
be even faster ;-)

Nb2. Anything else you do after this code will now show your preferred
sample labels instead of the .cel file names.

Hope that helps,

Best wishes,


On Fri, Mar 28, 2008 at 10:26 AM, IAIN GALLAGHER
<iaingallagher at btopenworld.com> wrote:
> Hi All.
>  I am clustering affymetrix expression data using hclust. I would like

> to label the tree with the sample name and group from which the sample

> comes from. I can generate a vector of labels from my phenoData slot
>  eg
>  graph_labels <- paste(pData(rma_data)$group, pData(rma_data)$label, 
> sep=' : ')
>  but I can't get them to sit on the right branches using
>  plot (clust, labels = graph_labels).
>  I suspect this has to do with the labeling in the dist object.
>  I was wondering if there was a way to change the labels in the dist
object to reflect my preferred labeling or a way to quickly re-order my
preferred labeling vector to match that of the dist object.

Hi, Iain.

What you are showing looks to be the correct way to go about things.
The labels will be reordered as necessary, I believe.  However, since we
cannot see how you created the "clust" object, it is impossible to tell
where the problem might be.  Only after you post all the relevant code
can anyone really help you.  Also, it is a really good idea to post the
output of sessionInfo() for every question to the list.  Even if it
isn't important, no one will ever fault you for doing so.


The University of Aberdeen is a charity registered in Scotland, No SC013683.

More information about the Bioconductor mailing list