Let's say I have this graph (The code to generate the graph is at the end)
How can I extract all the leaves comming from, let's say "cluster3"?, i.e. {100, 92, 87, 89}
I guess I have to first extract the subgraph with "cluster3" as root vertex
and then filter the result. This last part should be easy.
What I'm finding hard to get is extracting the subgraph. I tried using the Subgraph functions doing like:
Subgraph[myGraph, UndirectedEdge[_, cluster3]]
But I don't get what I want
Probably this is trivial and I'm just not seeing it. Any kind of help would be super useful.
Thanx!
This is what I used to create the graph
Needs["HierarchicalClustering`"];
MakeClusteredTree[data_,leaves_,opts:OptionsPattern[]]:=Module[{clusters,expr,ett,edges,optsGraph=FilterRules[opts,Options[Graph]],optsAgglomerate=FilterRules[opts,Options[Agglomerate]]},clusters=Agglomerate[data->leaves,optsAgglomerate];expr=(i=1;Replace[clusters,Cluster[a_,b_,___]:>Symbol["cluster"<>ToString[i++]][a,b],{0,Infinity}]);ett=SparseArray`ExpressionToTree[expr];edges=UndirectedEdge@@@(ett[[All,All,1]]);Graph[(UndirectedEdge@@@edges),GraphLayout->{"LayeredEmbedding","RootVertex"->(UndirectedEdge@@@edges)[[1,1]]},VertexLabels->"Name",optsGraph,ImagePadding-> Full]]
data = {100, 43, 87, 1, 49, 32, 79, 42, 89, 92};
MakeClusteredTree[data, ToString /@ data, {Linkage -> "Average"}]
====Final Notes====
The MakeClusteredTree function is completely based on this post (highest of high fives to kguler). I just changed it a little bit for my original purpose and another little bit for this post (I'm using more complicated data, huge trees and originally, I only visibly label the leaves. I changed the VertexLabels for this example so I can show you the names of all nodes.