Overview
The following example demonstrates how you can use a variable in a Graphics Script whose value changes over iterations of a For() loop. To make this work as desired, you must replace the variable with its value during each iteration. You can accomplish this using Substitute() or Eval Expr(), as demonstrated in the below example.
The Eval Expr() function evaluates and replaces any variable wrapped in the Expr() function with its current value. An outer Eval() function evaluates the entire statement after the replacement has occurred. See the embedded comments for further details.
Instructions
In a JMP® session, click the File menu and select New ► Script. Copy the below script and paste it into the script window. To run the sample script, click the Edit menu and select Run Script.
Names Default To Here( 1 );
/* Open a sample data table */
dt = Open( "$SAMPLE_DATA\Fitness.jmp" );
/* Generate the desired analysis */
biv = dt << Bivariate( Y( :Runtime ), X( :Age ), Fit Mean( {Line Color( {212, 73, 88} )} ), By( :Sex ) );
rbiv = biv << Report;
//Calculate the mean age by gender
Summarize( dt, b = By( :Sex ), mAge = Mean( :Age ) );
/* Loop through each level of the By variable */
For( i = 1, i <= N Items( rbiv ), i++,
var = mAge[i];
/* Evaluate entire statement after var is replaced with its current value */
Eval(
/* Evaluate and replace var with its value */
Eval Expr( rbiv[i][FrameBox( 1 )] << Add Graphics Script( V Line( Expr( var ) ) ) )
);
);
Additional Documentation
More information about the JMP Scripting Language can be found in the Scripting Guide available in the online help.
[Previously JMP Note 55553]