Our World Statistics Day conversations have been a great reminder of how much statistics can inform our lives. Do you have an example of how statistics has made a difference in your life? Share your story with the Community!
Choose Language Hide Translation Bar
Highlighted
Level V

## Get rows currently displayed on a dendrogram

Hello,

I would like to know if there is a way to know which individuals are currently displayed on a dendrogram after a zooming action.

Here is an example:

``````Names Default To Here( 1 );
dt = Open( "\$SAMPLE_DATA/Birth Death Subset.jmp" );
Hierarchical Cluster(
Y( :birth, :death ),
Label( :country ),
Method( "Ward" ),
Standardize Data( 1 ),
Dendrogram Scale( "Distance Scale" ),
Number of Clusters( 4 ),
SendToReport(
Dispatch( {}, "Dendrogram", OutlineBox, {SetHorizontal( 1 )} ),
Dispatch(
{"Dendrogram"},
"2",
ScaleBox,
{Min( 18 ), Max( 31 ), Inc( 5 ), Minor Ticks( 0 )}
)
)
);``````

I would like to get the list of the 13 countries selected.

A good solution, I think, would be to get the min and max values (18 and 31) but so far I can't find how to extract them...

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Community Manager

## Re: Get rows currently displayed on a dendrogram

Hi @anne_sa,

I don't know of a direct way to get those rows, but since the Min and Max information is part of the script for the platform, and because we can save the display order of the rows in the dendrogram, we can script our way to the result with a little work. It's not altogether elegant, but here's one way I came up with:

``````
Names Default To Here( 1 );
dt = Open( "\$SAMPLE_DATA/Birth Death Subset.jmp" );

hcPlatform = Hierarchical Cluster(
Y( :birth, :death ),
Label( :country ),
Method( "Ward" ),
Standardize Data( 1 ),
Dendrogram Scale( "Distance Scale" ),
Number of Clusters( 4 ),
SendToReport(
Dispatch( {}, "Dendrogram", OutlineBox, {SetHorizontal( 1 )} ),
Dispatch( {"Dendrogram"}, "2", ScaleBox, {Min( 18 ), Max( 31 ), Inc( 5 ), Minor Ticks( 0 )} )
)
);

//save the order displayed in the platform
displayOrd = hcPlatform << Save Display Order;

//get the script, which contains the Min() and Max() information
exprPlat = hcPlatform << Get Script;

//Extract the Min and Max. This is indexed in the reverse of the Display Order
//that is, the max value is the first in the order (as if it is an axis), so subtracting
//this value from the number of rows in the table brings things into alignment

minOrder = 1 + N Rows( dt ) - Arg( Extract Expr( exprPlat, Max( Wild() ) ) );
maxOrder = N Rows( dt ) - Arg( Extract Expr( exprPlat, Min( Wild() ) ) );

//select the rows in the table that meet the condition of being in the randge displayed
dt << Select Where( And( As Column( displayOrd ) >= minOrder, As Column( displayOrd ) <= maxOrder ) );

//get the matrix of row numbers for the selected rows, i.e., rows displayed in zoom
matchingRows = dt << get selected rows;``````

I hope this helps!

7 REPLIES 7
Highlighted
Community Manager

## Re: Get rows currently displayed on a dendrogram

Hi @anne_sa,

I don't know of a direct way to get those rows, but since the Min and Max information is part of the script for the platform, and because we can save the display order of the rows in the dendrogram, we can script our way to the result with a little work. It's not altogether elegant, but here's one way I came up with:

``````
Names Default To Here( 1 );
dt = Open( "\$SAMPLE_DATA/Birth Death Subset.jmp" );

hcPlatform = Hierarchical Cluster(
Y( :birth, :death ),
Label( :country ),
Method( "Ward" ),
Standardize Data( 1 ),
Dendrogram Scale( "Distance Scale" ),
Number of Clusters( 4 ),
SendToReport(
Dispatch( {}, "Dendrogram", OutlineBox, {SetHorizontal( 1 )} ),
Dispatch( {"Dendrogram"}, "2", ScaleBox, {Min( 18 ), Max( 31 ), Inc( 5 ), Minor Ticks( 0 )} )
)
);

//save the order displayed in the platform
displayOrd = hcPlatform << Save Display Order;

//get the script, which contains the Min() and Max() information
exprPlat = hcPlatform << Get Script;

//Extract the Min and Max. This is indexed in the reverse of the Display Order
//that is, the max value is the first in the order (as if it is an axis), so subtracting
//this value from the number of rows in the table brings things into alignment

minOrder = 1 + N Rows( dt ) - Arg( Extract Expr( exprPlat, Max( Wild() ) ) );
maxOrder = N Rows( dt ) - Arg( Extract Expr( exprPlat, Min( Wild() ) ) );

//select the rows in the table that meet the condition of being in the randge displayed
dt << Select Where( And( As Column( displayOrd ) >= minOrder, As Column( displayOrd ) <= maxOrder ) );

//get the matrix of row numbers for the selected rows, i.e., rows displayed in zoom
matchingRows = dt << get selected rows;``````

I hope this helps!

Highlighted
Super User

## Re: Get rows currently displayed on a dendrogram

Very nicely done.
Jim
Highlighted
Level V

## Re: Get rows currently displayed on a dendrogram

Hi @julian,

Thank you so much for this fast answer it is exactly what I was looking for!!!

I just have a small additionnal question: is there a way to detect that a zooming action has been done on the dendrogram? Maybe something based on the <<On change feature, but I am not sure it is compatible with the Hierarchical Clustering platform...

Highlighted
Community Manager

## Re: Get rows currently displayed on a dendrogram

Hi @anne_sa,

That's a great idea, but I haven't found an easy way to make that happen. How about a button on the bottom of the window to invoke the selection?

``````Names Default To Here( 1 );
dt = Open( "\$SAMPLE_DATA/Birth Death Subset.jmp" );

hcPlatform = Hierarchical Cluster(
Y( :birth, :death ),
Label( :country ),
Method( "Ward" ),
Standardize Data( 1 ),
Dendrogram Scale( "Distance Scale" ),
Number of Clusters( 4 ),
SendToReport(
Dispatch( {}, "Dendrogram", OutlineBox, {SetHorizontal( 1 )} ),
Dispatch( {"Dendrogram"}, "2", ScaleBox, {Min( 18 ), Max( 31 ), Inc( 5 ), Minor Ticks( 0 )} )
)
);

//save the order displayed in the platform
displayOrd = hcPlatform << Save Display Order;

selectZoom = expr(
//get the script, which contains the Min() and Max() information
exprPlat = hcPlatform << Get Script;

//Extract the Min and Max. This is indexed in the reverse of the Display Order
//that is, the max value is the first in the order (as if it is an axis), so subtracting
//this value from the number of rows in the table brings things into alignment

minOrder = 1 + N Rows( dt ) - Arg( Extract Expr( exprPlat, Max( Wild() ) ) );
maxOrder = N Rows( dt ) - Arg( Extract Expr( exprPlat, Min( Wild() ) ) );

//select the rows in the table that meet the condition of being in the randge displayed
dt << Select Where( And( As Column( displayOrd ) >= minOrder, As Column( displayOrd ) <= maxOrder ) );

//get the matrix of row numbers for the selected rows, i.e., rows displayed in zoom
matchingRows = dt << get selected rows;

);

//add the button to the report
report(hcPlatform)<<Append(ButtonBox("Select Zoomed Rows in Table",selectZoom));``````

Highlighted
Super User

## Re: Get rows currently displayed on a dendrogram

You can attach a graphics script

to the dendograph framebox.  It will trigger anytime something is done to the graph.  In the added script, you can check to see if the minOrder or MaxOrder have changed.

Jim
Highlighted
Community Manager

## Re: Get rows currently displayed on a dendrogram

Ah, there we go. Should have thought of that one!

//Edit: Adding that graphics script seems to interfere with the double-click to zoom on selected cluster. There's certainly some way to make it work, but the button seems fairly foolproof at the moment, especially if you want to be able to select individuals in the dendrogram but then reestablish the selection to the current zoom.

Highlighted
Level V

## Re: Get rows currently displayed on a dendrogram

Hi @txnelson ,

I have never used this functionnality but it trully enlarges the possibilities of JMP, that's so nice!!

In my situation I do not really need to select the rows but just to get the minOrder and maxOrder values. That's why I think there won't be interference issue as mentionned by @julian . I need to test that :)

Thanks again both of you for your help!

Article Labels

There are no labels assigned to this post.