cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
JMP is taking Discovery online, April 16 and 18. Register today and join us for interactive sessions featuring popular presentation topics, networking, and discussions with the experts.
Choose Language Hide Translation Bar
Thierry_S
Super User

Graph Builder: calculating axis Max, Min, and Range for dynamic annotation placement

Hi JMP community,

 

I have a script that plots data from a series of columns in one table grouped based on a variable (:VAR_CAT), and that adds dynamically text from another table, using Graph Builder. While this script works well, I have experienced some difficulty with the vertical placement of the dynamically added text (see script below).

 

Specifically, I tried different approaches including:

  1. YMax = Col Mean (YCOL) + (Col Std Dev (YCOL)/sqrt(Col Number(YCOL))); but this does not work well enough because this returns the YMAX for the entire column and not for the subset defined by the Overlay variable --> what would be the correct lines of code to calculate dynamically the actual Y axis maximum for the data grouped into Overlay categories (I know that the "By" option only works within a For Each Row structure)?
  2. YMAX = report (gb)[Axis Box (2)] << Get Max; which retrieves the actual Maximum for the GB Y Axis but this approach would force me to Evaluate the expression a second time which does not seem efficient or elegant
Names Default to Here (1);

dt1 = Data Table ("DATA_TABLE.JMP");
dt2 = Data Table ("PVALUE_TABLE.JMP");
CList = dt1 << Get Column Names(string);

	gbe = Expr (Graph Builder(
				Size( 497, 507 ),
				Variables(
					X( :DURATION ),
					Y( _YS_ ),
					Overlay( :VAR_CAT ),
					Interval( _ES_)
				),
				Elements( Points( X, Y, Legend( 9 ) ), Line( X, Y, Legend( 11 ) ) ),
				SendToReport(
					Dispatch(
						{},
						_LABEL_,
						ScaleBox,
						{Add Ref Line( 0, "Dotted", "Black", "", 2 )}
					),
					Dispatch(
						{},
						"DURATION",
						ScaleBox,
						{Min( -1.0 ), Max( 16 ), Inc( 2 ), Minor Ticks( 0 )}
					),
					Dispatch(
						{},
						"400",
						ScaleBox,
						{Legend Model(
							9,
							Base( 0, 0, 0, Item ID( "CAT1", 1 ) ),
							Base( 1, 0, 0, Item ID( "CAT2", 1 ) )
						)}
					),
					
					Dispatch(
						{},
						"Graph Builder",
						FrameBox,
						{Marker Size( 6 ), Add Graphics Script(
							2,
							Description( "Script" ),
							Text( Center Justified, {3.8, _TP_}, _TXT1_ );
							Text( Center Justified, {13.6, _TP_}, _TXT2_ );
						), Grid Line Order( 1 ), Reference Line Order( 3 )}
					)
				)
			)
		);
For (i = 5, i <= 96, i++, //96

	YCOL = Column (dt1, i);
	ECOL = Column (dt1, i+92);
	LBL = CList [i];
	
	YMax = Col Mean (YCOL) + (Col Std Dev (YCOL)/sqrt(Col Number(YCOL)));
	YMin = Col Mean (YCOL) - (Col Std Dev (YCOL)/sqrt(Col Number(YCOL)));
	
	YRANGE = abs (YMax - Y Min);
	
	If (YRANGE < 1.0, 
							YMax = YMax + 0.5;
							YMin = YMin - 0.3	
							);
	
	TOPY = YMax-0.1;
	
	
	PVAL1 = "p VAL " || CHAR(Format(Column(dt2, 2)[i-4], "PValue"));
	PVAL2 = "p VAL " || CHAR(Format(Column(dt2, 3)[i-4], "PValue"));
	
	gbx = Substitute (Name Expr (gbe), 	Expr (_YS_), YCOL,
										Expr (_ES_), ECOL,
										Expr (_LABEL_), LBL,
										Expr (_TP_), TOPY,
										Expr (_TXT1_), PVAL1,
										Expr (_TXT2_), PVAL2
											
					);
	gb = Eval (gbx);
	
	Yaxis = report (gb)[Axis Box (2)];
	
	LocYMin = Yaxis << Get Min;
	LocYMax = Yaxis << Get Max;
	
	LocRange = LocYMax - LocYMin;
	
	mytitle = substitute (LBL, "Least Sq Mean LOG2 FC ", "");
	
	report (gb) [OutlineBox (1)] << Set Title (mytitle);
		
	if(abs (LocRange) < 1.0, 
		Yaxis << Max (LocYMax + 0.5);
		Yaxis << Min (LocYMin - 0.3);
		Yaxis << Inc (0.2),.);

	
	gb << Journal;
	gb << close window;
	

);			
Thierry R. Sornasse
2 ACCEPTED SOLUTIONS

Accepted Solutions
Jeff_Perkinson
Community Manager Community Manager

Re: Graph Builder: calculating axis Max, Min, and Range for dynamic annotation placement

You can get the script for the axis box and then find the arguments for the Min() and Max() settings.

 

dt = Open( "$SAMPLE_DATA\Big Class.jmp" );
biv = Bivariate( Y( :weight ), X( :height ), Fit Line( {Line Color( {212, 73, 88} )} ) );
y_axis_script = Report( biv )[axis box( 1 )] << get script;

/*
y_axis_script will be a list: {Scale( "Linear" ), Format( "Fixed Dec", 12, 0 ), Min( 60 ), Max( 180 ),
Interval( "Numeric" ), Inc( 20 ), Minor Ticks( 0 ), Label Row Nesting( 1 ),
Label Row(
	{Automatic Font Size( 0 ), Automatic Tick Marks( 0 ), Inside Ticks( 0 ),
	Label Alignment( "Near" ), Label Buffer Scale( 1 ),
	Label Orientation( "Horizontal" ), Lax Label Range( 0 ),
	Major Grid Line Color( -14145495 ), Minimum Depth( 0 ), Minimum Font Size( 8 ),
	Minor Grid Line Color( -15790320 ), Show Major Grid( 0 ), Show Major Labels( 1 ),
	Show Major Ticks( 1 ), Show Minor Grid( 0 ), Show Minor Labels( 0 ),
	Show Minor Ticks( 1 ), Tick Offset( 0 ), Wrap Lines( 0 )}
)}
*/

//get the arguments for the 3rd and 4th elements of that list
minimum = Arg( y_axis_script[3], 1 );
maximum = Arg( y_axis_script[4], 1 );

 

-Jeff

View solution in original post

Re: Graph Builder: calculating axis Max, Min, and Range for dynamic annotation placement

You can also ask the axis box directly:

 

Names Default To Here( 1 );
Open( "$SAMPLE_DATA/Big Class.jmp" );
biv = Bivariate( Y( :weight ), X( :height ), FitLine );
rbiv = biv << report;
axisbox = rbiv[axis box( 1 )];
axisbox << Get Max;

(From Help > Scripting Index)

View solution in original post

4 REPLIES 4
pauldeen
Level VI

Re: Graph Builder: calculating axis Max, Min, and Range for dynamic annotation placement

Try adding one of these to the elements list of the graph builder:

Caption Box( Y, Legend( 4 ), Summary Statistic( "Max" ) )

so:

gbe = Expr (Graph Builder(
				Size( 497, 507 ),
				Variables(
					X( :DURATION ),
					Y( _YS_ ),
					Overlay( :VAR_CAT ),
					Interval( _ES_)
				),
				Elements(
                                  Points( X, Y, Legend( 9 ) ),
                                  Line( X, Y, Legend( 11),
                                  Caption Box( Y, Legend( 4 ), Summary Statistic( "Max" ) )
) ),
//the rest of your code

    You can do this visually by right clicking in the Graph Builder and adding a caption box. Then in the list on the left change the summary statistics to what you need and change the variables it uses for the calculation.

Thierry_S
Super User

Re: Graph Builder: calculating axis Max, Min, and Range for dynamic annotation placement

Hi,
Thank you for providing this suggestion but I don't think it addresses my problem. I may not have provided a clear description of my issue: what I'm trying to achieve is to calculate from the data or to extract from GB the Y axis Maximum in order to place accurately the dynamic Text Script content to the graph.

Maybe you meant to suggest that I should use a Caption Box instead of direct Text Script to dynamically annotate my plots. If it is the case, I'm not sure if it is possible to dynamically replace the text content from a Caption Box (please, correct me if I'm wrong).

Thank you for your help.
Sincerely,
TS
Thierry R. Sornasse
Jeff_Perkinson
Community Manager Community Manager

Re: Graph Builder: calculating axis Max, Min, and Range for dynamic annotation placement

You can get the script for the axis box and then find the arguments for the Min() and Max() settings.

 

dt = Open( "$SAMPLE_DATA\Big Class.jmp" );
biv = Bivariate( Y( :weight ), X( :height ), Fit Line( {Line Color( {212, 73, 88} )} ) );
y_axis_script = Report( biv )[axis box( 1 )] << get script;

/*
y_axis_script will be a list: {Scale( "Linear" ), Format( "Fixed Dec", 12, 0 ), Min( 60 ), Max( 180 ),
Interval( "Numeric" ), Inc( 20 ), Minor Ticks( 0 ), Label Row Nesting( 1 ),
Label Row(
	{Automatic Font Size( 0 ), Automatic Tick Marks( 0 ), Inside Ticks( 0 ),
	Label Alignment( "Near" ), Label Buffer Scale( 1 ),
	Label Orientation( "Horizontal" ), Lax Label Range( 0 ),
	Major Grid Line Color( -14145495 ), Minimum Depth( 0 ), Minimum Font Size( 8 ),
	Minor Grid Line Color( -15790320 ), Show Major Grid( 0 ), Show Major Labels( 1 ),
	Show Major Ticks( 1 ), Show Minor Grid( 0 ), Show Minor Labels( 0 ),
	Show Minor Ticks( 1 ), Tick Offset( 0 ), Wrap Lines( 0 )}
)}
*/

//get the arguments for the 3rd and 4th elements of that list
minimum = Arg( y_axis_script[3], 1 );
maximum = Arg( y_axis_script[4], 1 );

 

-Jeff

Re: Graph Builder: calculating axis Max, Min, and Range for dynamic annotation placement

You can also ask the axis box directly:

 

Names Default To Here( 1 );
Open( "$SAMPLE_DATA/Big Class.jmp" );
biv = Bivariate( Y( :weight ), X( :height ), FitLine );
rbiv = biv << report;
axisbox = rbiv[axis box( 1 )];
axisbox << Get Max;

(From Help > Scripting Index)