[R] dendrogram again
Gavin Simpson
gavin.simpson at ucl.ac.uk
Fri Mar 9 13:52:35 CET 2007
On Fri, 2007-03-09 at 12:17 +0100, bunny , lautloscrew.com wrote:
> Hi all,
>
> ok, i know i can cut a dendrogram, which i did.
> all i get is three objects that a dendrograms itself.
>
> for example:
> myd$upper, myd$lower[[1]], myd$lower[[2]]
> and so on. of course i can plot them seperately now.
>
> but the lower parts still have hundreds of branches. i´ll need a 30 "
> widescreen to watch the whole picture.
> what i´d like to is group the lower branches , so that i get a
> dendrogram with a few branches, splitting only in the upper levels.
> In terms of the cluster analysis, i just want to have a few bigger
> clusters.
>
> thx,
>
> m.
>
> P.S.:
> putting parts of a cutted dendrogram back into to one could be an
> idea ? is it somehow possible ?
Again, perhaps I'm missing something, but if I understand you correctly
(again no example I can follow - what is myd and how did you create
it?), you only want to plot the upper part of the dendrogram and not the
lower branches. If so, then this /is/ on ?dendrogram and you /do/ use
cut() to do it ...:
'cut.dendrogram()' returns a list with components '$upper' and
'$lower', the first is a truncated version of the original tree,
also of class 'dendrogram', the latter a list with the branches
obtained from cutting the tree, each a 'dendrogram'.
So to only show the pruned tree, you just plot $upper - it does say that
$upper is a dendrogram and that it is the truncated version of the
original tree - which is what I understand you to be asking for. This
example shows it in action - this is what I mean by a reproducible
example - (I'm using package vegan as I am familiar with this data set):
require(vegan) ## if false install it
data(varespec)
hc <- hclust(vegdist(varespec, "bray"), method = "ward")
hc <- as.dendrogram(hc)
## this is the full dendrogram - too many nodes, so prune
plot(hc)
## lets take four clusters and prune it back
hc.pruned <- cut(hc, h = 1) # can't specify k so read height of first
# plot - cutting at h = 1 gives 4 clusters
# plot only the upper part of the tree showing only the 4 clusters
plot(hc.pruned$upper, center = TRUE)
Is this what you want? If not, using the example I provide above, tell
us exactly what you want to achieve.
HTH
G
--
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
Gavin Simpson [t] +44 (0)20 7679 0522
ECRC, UCL Geography, [f] +44 (0)20 7679 0565
Pearson Building, [e] gavin.simpsonATNOSPAMucl.ac.uk
Gower Street, London [w] http://www.ucl.ac.uk/~ucfagls/
UK. WC1E 6BT. [w] http://www.freshwaters.org.uk
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
More information about the R-help
mailing list