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:
- 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)?
- 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