Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I want to create a dendrogram with the labels being a visual representation of the data. Something like this: What I wanna do

How can I do that in Mathematica? My attempt so far hasn't been very successful. The labels are all messed up.

Needs["HierarchicalClustering`"]
SeedRandom@2;
data = RandomVariate[NormalDistribution[], {10, 20}];
label = ListPlot[#, Axes -> False, Joined -> True] & /@ data;
DendrogramPlot[data, Orientation -> Right, LeafLabels -> label]

This is what I get from the code above:

enter image description here

share|improve this question

1 Answer 1

up vote 5 down vote accepted

Straightforward approach with controlling related heights.

Needs["HierarchicalClustering`"]
SeedRandom@2;
data = RandomVariate[NormalDistribution[], {10, 20}];

height = 50;
label = ListPlot[#, Axes -> False, Joined -> True, ImageSize -> {300, height}, 
                    AspectRatio -> height/300] & /@ data;

Edit I'm sorry my previous version has not included correct order of the samples.

With[{h = Length[data] height, 
      plot = Reap@DendrogramPlot[data, LeafLabels -> (Sow@Position[data, #][[1, 1]] &),  
                                       Orientation -> Right]
     },
 Row[{
      Column[label[[plot[[2, 1]]]], Spacings -> 0],
      Show[plot[[1]], ImageSize->{300, h},  AspectRatio -> h/300, 
                      ImagePadding -> {{10, 0}, {height/2, height/2}}]
 }]]

enter image description here

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.