Choose Language Hide Translation Bar
Highlighted
Thierry_S
Community Trekker

GraphBuilder Loop Script Problem: Added Text Position Changes With Each Iteration (see Script below)

Hi JMP Community,

I put together a relatively simple script where I add dynamically some text for which I adjust the Y position based on the scale of the graph (see below and attached data example). Oddly, when I run through the loop, the Y position of the added text changes with each iteration. Hence, I end up with the added text Y position set for the last graph in the series which is not desirable. Is there a trick to "lock" the added text Y position for each graphs?

 

Names Default to Here (1);

dt = current datatable ();

CoList = dt << get column names (string);

try( close( dt1, nosave ) );
((dt << Tabulate(invisible,
						Add Table(
							Column Table( Grouping Columns( :VISIT ) ),
							Row Table( Grouping Columns( :SHORT TAG ) )
						)
						)) << Make Into Data Table) << Set Name ("TEMP");
						
dt1 = data table ("TEMP");
						
CCount = column (dt1, "BL");

Data Table (dt);

LMin = -1.5;
LMax = 0.5;

For (i= 5, i<=8, i++, 
	
	LMin = Col Mean (Column (i)) -1;
	LMax = Col Mean (Column (i)) +1;
	POS_Y = LMin + 0.25;
		
	gb = Expr (Graph Builder(
						Size( 1061, 524 ),
						Lock Scales( 1 ),
						Variables(
							X( :Name( "DURATION (Week)" ) ),
							Y( column (i) ),
							Group X( :LEAD TAG ),
							Overlay( :SHORT TAG )
						),
						Elements(
							Line( X, Y, Legend( 4 ), Smoothness( 0.5 ) ),
							Points(
								X,
								Y,
								Legend( 5 ),
								Summary Statistic( "Mean" ),
								Error Bars( "Standard Error" ),
								Jitter( "None" ),
								Jitter Limit( 0 )
							)
						),
						SendToReport(
							Dispatch(
								{},
								"DURATION (Week)",
								ScaleBox,
								{Format( "Fixed Dec", 12, 0 ), Min( -1 ), Max( 27 ), Inc( 2 ),
								Minor Ticks( 1 ), Add Ref Line( 14, "Solid", "Black", "", 2 )}
							),
							Dispatch(
								{},
								_TXT_,
								ScaleBox,
								{Format( "Fixed Dec", 12, 1 ), Min( LMin ), Max( LMax ), Inc( 0.5 ),
								Minor Ticks( 1 ), Add Ref Line( 0, "Dotted", "Black", "", 2 ),
								Label Row( {Set Font Size( 12 ), Set Font Style( "Plain" )} )}
							),
							Dispatch(
								{},
								"",
								ScaleBox,
								{Format( "Fixed Dec", 12, 2 ), Min( -0.5 ), Max( 0.5 ), Inc( 0.25 ),
								Minor Ticks( 0 )}
							),
							Dispatch(
								{},
								"X title",
								TextEditBox,
								{Set Font Size( 12 ), Set Font Style( "Bold" )}
							),
							Dispatch(
								{},
								"Y title",
								TextEditBox,
								{Set Font Size( 12 ), Set Font Style( "Bold" )}
							),
							Dispatch(
								{},
								"Graph Builder",
								FrameBox,
								{Marker Size( 6 ), Left( 1 ), Right( 1 ), Top( 0 ), Bottom( 1 ),
								Add Graphics Script(
									2,
									Description( "Script" ),
									Text Size (10);
									Text Color ("Dark Red");
									Text( Center Justified, {21, POS_Y}, N1 );
									Text Color ("Light Red");
									Text( Center Justified, {21, POS_Y-0.1}, N2 );
								), Grid Line Order( 1 ), Reference Line Order( 3 )}
							),
							Dispatch(
								{},
								"Graph Builder",
								FrameBox( 2 ),
								{Marker Size( 6 ), Left( 0 ), Right( 1 ), Top( 0 ), Bottom( 1 ),
								Add Graphics Script(
									2,
									Description( "Script" ),
									Text Size (10);
									Text Color ("Dark Green");
									Text( Center Justified, {21, POS_Y}, N3 );
									Text Color ("Light Green");
									Text( Center Justified, {21, POS_Y-0.1}, N4 );
								), Grid Line Order( 1 ), Reference Line Order( 3 )}
							),
							Dispatch(
								{},
								"Graph Builder",
								FrameBox( 3 ),
								{Marker Size( 6 ), Add Graphics Script(
									2,
									Description( "Script" ),
									Text Size (10);
									Text Color ("Dark Blue");
									Text( Center Justified, {21, POS_Y}, N5 );
									Text Color ("Light Blue");
									Text( Center Justified, {21, POS_Y-0.1}, N6 );
								), Grid Line Order( 1 ), Reference Line Order( 3 )}
							)
						)
					)
				);
		gbe = Eval (Substitute (Name Expr (gb), Expr (_TXT_), CoList [i],
							Expr (N1), 	"UPA > UPA (n=" || char(CCount [1]) || ")",
							Expr (N2), 	"UPA > ADA (n=" || char(CCount [2]) || ")", 
							Expr (N3), 	"ADA > ADA (n=" || char(CCount [3]) || ")", 
							Expr (N4), 	"ADA > UPA (n=" || char(CCount [4]) || ")", 
							Expr (N5), 	"PBO > PBO (n=" || char(CCount [5]) || ")", 
							Expr (N6), 	"PBO > UPA (n=" || char(CCount [6]) || ")"  
							));	
		gbe << journal;
		gbe << close window;
);

Close (dt1, NoSave); 
Thierry R. Sornasse
0 Kudos