cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Try the Materials Informatics Toolkit, which is designed to easily handle SMILES data. This and other helpful add-ins are available in the JMP® Marketplace
Choose Language Hide Translation Bar
Thierry_S
Super User

WINDOWS 10 > JMP 17.2 > Graph Builder > Scatter Plot > Dynamic Cluster Annotation

Hi JMP Community,

 

Windows Pro 10 - JMP 17.2

 

I have some data projected on a 2D UMAP, and I would like to automatically insert the formatted (Color and Size) Cluster ID on top of the UMAP2 x UMAP1 Scatter Plot in Graph Builder. I managed to get the Cluster IDs by plotting them separately and merging them to the main FrameBox. Still, this is unsatisfactory because I cannot control the size and color of those Cluster ID labels.

 

I experimented with a Loop within an Add Graphics Script() command but could not make it work.

 

Thierry_S_0-1735364165556.png

Here is the script I used to produce the plot above

Names Default to Here(1);

dt = Data Table ("ANNOTATION of 2D CLUSTERS");

dt_sum = dt << Summary(
	Group( :WARD UMAP CLUSTERS ),
	Mean( :UMAP1 CENTER by CLUSTER ),
	Mean( :UMAP2 CENTER by CLUSTER ),
	Freq( "None" ),
	Weight( "None" ),
	statistics column name format( "column" )
);

gb = dt << Graph Builder(
				Size( 483, 675 ),
				Fit to Window( "Off" ),
				Page Level Fill Color( "White" ),
				Graph Spacing( 15 ),
				Spacing Borders( 1 ),
				Variables( X( :UMAP1 ), Y( :UMAP2 ), Color( :WARD UMAP CLUSTERS ) ),
				Elements( Points( X, Y, Legend( 27 ) ) )
			);

gbr = report (gb);

main_x_max = gbr [AxisBox(1)] << Get Max;
main_x_min = gbr [AxisBox(1)] << Get Min;

main_y_max = gbr [AxisBox(2)] << Get Max;
main_y_min = gbr [AxisBox(2)] << Get Min;

F_size = gbr[FrameBox(1)] << Get Size;

xbe = Expr(dt_sum << Graph Builder(
			Size( _W_, _H_ ),
			Fit to Window( "Off" ),
			Page Level Fill Color( "White" ),
			Graph Spacing( 15 ),
			Spacing Borders( 1 ),
			Variables(
				X( :UMAP1 CENTER by CLUSTER ),
				Y( :UMAP2 CENTER by CLUSTER ),
				Color( :WARD UMAP CLUSTERS )
			),
			Elements(
				Bar( X, Y, Legend( 4 ), Bar Style( "Float" ), Label( "Label by Row" ) )
			)
		)
	);	
xbx = Substitute(Name Expr (xbe), 	Expr (_W_), F_Size [1],
									Expr (_H_), F_size [2]
);

xb = Eval (xbx);

xbr = report (xb);

xbr [AxisBox (1)] << max (main_x_max);
xbr [AxisBox (1)] << min (main_x_min);	

xbr [AxisBox (2)] << max (main_y_max);
xbr [AxisBox (2)] << min (main_y_min);

xbr [FrameBox(1)] << Copy Frame Contents;
gbr [FrameBox(1)] << Paste Frame Contents;

Thank you.

Best,

TS

 

Thierry R. Sornasse
1 ACCEPTED SOLUTION

Accepted Solutions
jthi
Super User

Re: WINDOWS 10 > JMP 17.2 > Graph Builder > Scatter Plot > Dynamic Cluster Annotation

I think your method is just fine. You can also use Arg() to get the items from the value colors list of "things". I would also evaluate the variables outside of the graphic script INSIDE the graphic script to avoid all sorts of annoying issues when the variables are lost.

 

I would most likely use Associative Array to collect ids, colors, x and y coordinates. One issue with this could be that Summarize and Associative Array might have different ordering and it would have to be taken into account (I haven't done it here).

 

Names Default To Here(1);

dt = Data Table("ANNOTATION of 2D CLUSTERS");

Summarize(
	dt,
	clu_id = By(:WARD UMAP CLUSTERS),
	x_pos = Mean(:UMAP1 CENTER by CLUSTER),
	y_pos = Mean(:UMAP2 CENTER by CLUSTER)
);

vect = dt:WARD UMAP CLUSTERS << Get Property("Value Colors");

aa_colors = Associative Array();

For Each({item, idx}, vect,
	aa_colors[Arg(item, 1)] = Associative Array();
	aa_colors[Arg(item, 1)]["Color"] = Arg(item, 2);
	aa_colors[Arg(item, 1)]["X"] = x_pos[idx];
	aa_colors[Arg(item, 1)]["Y"] = y_pos[idx];	
);

gb = dt << Graph Builder(
	Size(483, 675),
	Fit to Window("Off"),
	Page Level Fill Color("White"),
	Graph Spacing(15),
	Spacing Borders(1),
	Variables(X(:UMAP1), Y(:UMAP2), Color(:WARD UMAP CLUSTERS)),
	Elements(Points(X, Y, Legend(27)))
);

Eval(EvalExpr(
	Report(gb)[FrameBox(1)] << Add Graphics Script(
		Text Size (14);
		myaa = Expr(aa_colors);
		ids = myaa << get keys;
		For(i = 1, i <= N Items(ids), i++,
			Fill Color ("white");
			Transparency (0.85);
			Circle({myaa[ids[i]]["X"], myaa[ids[i]]["Y"] + 0.25}, 0.5, "FILL");
			Transparency(1);
			Text Color(myaa[ids[i]]["Color"]);
			Text(center justified, {myaa[ids[i]]["X"], myaa[ids[i]]["Y"]}, Char(ids[i]));
		);
	)
));

 

 

-Jarmo

View solution in original post

6 REPLIES 6
jthi
Super User

Re: WINDOWS 10 > JMP 17.2 > Graph Builder > Scatter Plot > Dynamic Cluster Annotation

You could add "extra" x and y-axis and then use those. Note that the color has been changed for the Mean(UMAP2) as it cannot be left as default or they will use Value Colors. You can also change the marker size to 0 i you don't want to highlight the "mean" point or change the marker

jthi_0-1735367411861.png

 

Graph Builder(
	Size(438, 629),
	Show Control Panel(0),
	Fit to Window("Off"),
	Page Level Fill Color("White"),
	Graph Spacing(15),
	Spacing Borders(1),
	Variables(
		X(:UMAP1),
		X(:UMAP1 CENTER by CLUSTER, Position(1)),
		Y(:UMAP2),
		Y(:UMAP2 CENTER by CLUSTER, Position(1)),
		Color(:WARD UMAP CLUSTERS)
	),
	Elements(
		Points(X(1), Y(1), Legend(27)),
		Points(
			X(2),
			Y(1),
			Color(0),
			Legend(32),
			Summary Statistic("Mean"),
			Label("Label by Row")
		)
	),
	SendToReport(
		Dispatch({}, "400", ScaleBox,
			{Legend Model(
				32,
				Properties(0, {Line Color(16)}, Item ID("Mean(UMAP2)", 1))
			)}
		)
	)
);

 

-Jarmo
Thierry_S
Super User

Re: WINDOWS 10 > JMP 17.2 > Graph Builder > Scatter Plot > Dynamic Cluster Annotation

Hi Jarmo,

Thank you for providing a much simpler solution to my initial challenge. Still, I would like to change the Labels' Font Size and Color to make the plot more readable. Do you have any clues on how I could achieve that task?

 

Best regards,

TS

 

Thierry R. Sornasse
jthi
Super User

Re: WINDOWS 10 > JMP 17.2 > Graph Builder > Scatter Plot > Dynamic Cluster Annotation

I think then you will have to utilize graphic script as labels do not have that many customization options (to change the text size you would have to change font preferences).

-Jarmo
hogi
Level XII

Re: WINDOWS 10 > JMP 17.2 > Graph Builder > Scatter Plot > Dynamic Cluster Annotation

Interesting, Labels of Bar graphs have a command to adjust the font, but point graph don't?
Graph builder bar chart data label control  -> interesting as well for other plot types?

 

Graph Builder(
	Variables( X( :WARD UMAP CLUSTERS ) ),
	Elements( Bar( X, Legend( 5 ), Label( "Label by Value" ) ) )
);

labels = (current report()[FrameBox(1)] << find segs)[1];


labels << Set Font( "", 18, "", 0 )
Thierry_S
Super User

Re: WINDOWS 10 > JMP 17.2 > Graph Builder > Scatter Plot > Dynamic Cluster Annotation

Hi All,

 

Once again, I tried to make it more complicated than necessary.

 

Here is the short JSL script I created, which does everything I needed. 

 

 

Names Default to Here(1);

dt = Data Table ("ANNOTATION of 2D CLUSTERS");

Summarize (dt, clu_id = By (:WARD UMAP CLUSTERS), x_pos = Mean (:UMAP1 CENTER by CLUSTER), y_pos = Mean(:UMAP2 CENTER by CLUSTER));

clu_n = N items (clu_id);

colors = {};

vect = dt:WARD UMAP CLUSTERS << Get Property ("Value Colors");
For (j = 1, j <= clu_n, j++,
	insert into(colors, num (word(-1, char(vect [j]), "=")))
);

gb = dt << Graph Builder(
	Size( 483, 675 ),
	Fit to Window( "Off" ),
	Page Level Fill Color( "White" ),
	Graph Spacing( 15 ),
	Spacing Borders( 1 ),
	Variables( X( :UMAP1 ), Y( :UMAP2 ), Color( :WARD UMAP CLUSTERS ) ),
	Elements( Points( X, Y, Legend( 27 ) ) ),
	SendToReport(
		Dispatch(
			{},
			"Graph Builder",
			FrameBox,
			{Add Graphics Script(
				10,
				Description( "" ),
				Text Size (14);
				For( i = 1, i <= clu_n, i++,
					Label = clu_id [i];
					Fill Color ("white");
					Transparency (0.85);
					Circle ({x_pos [i], y_pos [i]+0.25}, 0.5, "FILL");
					Transparency (1);
					Text Color (colors [i]);
					Text( center justified, {x_pos [i], y_pos [i]}, Label );
				)
			)}
		)
	)
);

Although I am unsure whether my crude method for collecting the Value Colors is efficient, it works.

 

Best,

 

TS

 

Thierry R. Sornasse
jthi
Super User

Re: WINDOWS 10 > JMP 17.2 > Graph Builder > Scatter Plot > Dynamic Cluster Annotation

I think your method is just fine. You can also use Arg() to get the items from the value colors list of "things". I would also evaluate the variables outside of the graphic script INSIDE the graphic script to avoid all sorts of annoying issues when the variables are lost.

 

I would most likely use Associative Array to collect ids, colors, x and y coordinates. One issue with this could be that Summarize and Associative Array might have different ordering and it would have to be taken into account (I haven't done it here).

 

Names Default To Here(1);

dt = Data Table("ANNOTATION of 2D CLUSTERS");

Summarize(
	dt,
	clu_id = By(:WARD UMAP CLUSTERS),
	x_pos = Mean(:UMAP1 CENTER by CLUSTER),
	y_pos = Mean(:UMAP2 CENTER by CLUSTER)
);

vect = dt:WARD UMAP CLUSTERS << Get Property("Value Colors");

aa_colors = Associative Array();

For Each({item, idx}, vect,
	aa_colors[Arg(item, 1)] = Associative Array();
	aa_colors[Arg(item, 1)]["Color"] = Arg(item, 2);
	aa_colors[Arg(item, 1)]["X"] = x_pos[idx];
	aa_colors[Arg(item, 1)]["Y"] = y_pos[idx];	
);

gb = dt << Graph Builder(
	Size(483, 675),
	Fit to Window("Off"),
	Page Level Fill Color("White"),
	Graph Spacing(15),
	Spacing Borders(1),
	Variables(X(:UMAP1), Y(:UMAP2), Color(:WARD UMAP CLUSTERS)),
	Elements(Points(X, Y, Legend(27)))
);

Eval(EvalExpr(
	Report(gb)[FrameBox(1)] << Add Graphics Script(
		Text Size (14);
		myaa = Expr(aa_colors);
		ids = myaa << get keys;
		For(i = 1, i <= N Items(ids), i++,
			Fill Color ("white");
			Transparency (0.85);
			Circle({myaa[ids[i]]["X"], myaa[ids[i]]["Y"] + 0.25}, 0.5, "FILL");
			Transparency(1);
			Text Color(myaa[ids[i]]["Color"]);
			Text(center justified, {myaa[ids[i]]["X"], myaa[ids[i]]["Y"]}, Char(ids[i]));
		);
	)
));

 

 

-Jarmo