Thank you for the support.
I was able to use the add Ref as you and @jthi suggested. I used the approach for coloration and confirmed it will work for a single distribution. When I add By conditions, I lose the plot addressing capability resulting in errors.
As suggested by @hogi I switched to available data for this question. To help facilitate the question I augmented Big Class in a modified version of Jim's script. Here are the steps I followed and the outcomes
1. Import Big Class
2. Conditionally add some data if the column "State" is not in the table
a. Add a column named State with sequenced data to place people in either "CA", "WA" or "OR".
b. Add a second "PATTY" who is 16, "F", 57, 134 and is in "WA".
3. Select some names. I chose LESLIE and PATTY
4. Run script to find and highlight bins of interest.
OK Case - remove By (:State)
from the script below and change the preceding comma to a semicolon to run successfully. The code finds both instances of Patty and uses different colors for each of them. If they had the same height, for this example the reference lines would overlap only showing one of the two colors.
@hogi made a good point about the arbitration of which color is shown. Once I understand the element addressing, I plan to add a conditional for the case where more than one interesting data point occurs in the same bin.
NG Case - run distribution with a By condition based on :State and see an error in addressing the plot object. I tried a few addressing permutations without success. I am missing key information to access the AxisBox.
Did not work either:
distRPT = Report( dist )["height",AxisBox( 1 )];
distRPT = Report( dist )["State=WA","height",AxisBox( 1 )];
distRPT = Report( dist["State=WA"] )["height",AxisBox( 1 )];
Sample error code: object not subscriptable at row 41 in access or evaluation of 'Report(dist)[ /*###*/AxisBox(1)]' , Report( dist )[/*###*/AxisBox( 1 )]
Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
col_name_list = dt << get column names(string);
newColName = "State";
// New column: State
if (!contains(col_name_list, newColName),
Local( {dt, tempStrings},
dt = Data Table( "Big Class" );
dt << New Column( "State", Character, "Nominal" ) << Begin Data Update;
tempStrings = {"CA", "WA", "OR"};
For Each Row( dt, :State = tempStrings[Sequence( 1, 3, 1, 1 )] );
dt << End Data Update;
);
//Make it a double Patty :), another person with the same name.
dt << Add Rows( 1, At End );
//Cheat and use a constant of 41 for the last row index
dt[[41],{name,age,sex,height,weight,State}] = {{"PATTY", 16, "F", 57, 134, "WA"}};
);
// For illustration, select some names
dt << select where( ContainsItem(:name, {"LESLIE","PATTY"}));
dist = dt << Distribution(
Stack( 1 ),
Continuous Distribution(
Column( :height ),
Quantiles( 0 ),
Summary Statistics( 0 ),
Horizontal Layout( 1 ),
Vertical( 0 ),
Set Bin Width( 2 ),
Process Capability( 0 )
),
By (:State)
);
distRPT = Report( dist )[AxisBox( 1 )];
// Find the Midpoints of the bins the selected rows are in
dist << Save( "Level Midpoints" );
theBins = (Associative Array( Column( dt, N Cols( dt ) )[dt << get selected rows] )) << get keys;
dt << delete columns( N Cols( dt ) );
// Get the Increment of the X axis
theIncr = distRPT[AxisBox( 1 )] << get inc;
// Add the reference lines for each selected bin
For Each( {bin, index}, theBins,
binList = {};
Insert Into( binList, bin - theIncr / 2 );
Insert Into( binList, bin + theIncr / 2 );
Eval( Eval Expr( distRPT << Add Ref Line( Expr( binList ), "Solid", Expr( Index + 2 ), "", 1, 0.25 ) ) );
);
Your comments and guidance are appreciated.
Thanks!
Bryan