[R] Dendrogram with the UPGMA method

Martin Maechler maechler at stat.math.ethz.ch
Tue Jan 20 21:30:13 CET 2009


>>>>> "MK" == Marcin Kozak <nyggus at gmail.com>
>>>>>     on Sat, 17 Jan 2009 10:14:10 +0100 writes:

    MK> Hi, I am clustering objects using the agnes() function
    MK> and the UPGMA clustering method (function =
    MK> "average"). Everything works well, but apparently
    MK> something is wrong with the dendrogram. For example:

    MK> x<-c(102,102.1,112.5,113,100.3,108.2,101.1,104,105.5,106.3)
    MK> y<-c(110,111,110.2,112.1,119.5,122.1,102,112,112.5,115)

    MK> xy<-cbind(x,y)

    MK> library(cluster) 
    MK> UPGMA.orig<-agnes(x)

well, you compute agnes() on the one-dimensional data x rather
than the 2D  xy 
...
but we know that this is not your main "problem"

    MK> plot(UPGMA.orig,which.plots=2,xlab="",main="",sub="")


    MK> Look how the dendrogram has been drawn: all the OTUs
    MK> should line up with 0.0 on the "distance" axis, 
"should" .. according to which commandments ?

    MK> but it is not the case in the dendrogram obtained here. Is it
    MK> possible to obtain a traditional dendrogram?

well, for those in the S / R tradition you already go a
traditional one...

but to finally help you:

use
	ag <- agnes(...)
	dg <- as.dendrogram(as.hclust(ag))
	plot(dg)

and if you read and look at the examples of

    help(plot.dendrogram)

you'll see that you have many more options for plotting there
(than if you'd plot the agnes object directly).

Martin Maechler, ETH Zurich
(being a bit disappointed that no other R-helper helped here ..)


    MK> (I am using R 2.7.0 with Windows XP)

    MK> Thanks and best wishes, Marcin




More information about the R-help mailing list