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:
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;
);
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 );
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)
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 codeYou 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.
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 );
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)