Hello,
I have a task to script some visualizations as table scripts. Normally this is simple. The rough part is the reference lines that need to reference other sources when the script is running. Due to the references being contained in two functions that don’t normally accept variables from the outside, finding out how to use expression manipulations to insert these values is something that is currently beyond my skill level. There are multiple obstacles to overcome.
- Functions that don’t accept outside variables well
- var1 = 1;
var2 = 2;
Dt << New script( “example”, print( var1 + var2 ) ); - Note that the variables are defined out of the table script. This is a requirement, as the numbers will be referenced from a data table.
- Dispatch()
- For values inside of this, they need to be static, plainly stated values
- Working with expressions that do not contain functions
- example = expr( New Script() );
title = “test”;
insert into( example, title ); // show(example) = New script( “test” )
// Later on when inserting cols into the x axis, as on line 22 of the example…
x_empty = expr( X() );
x_cols = { :col1, :col2 };
insert into( x_empty, x_cols[1] ); // errors out, JMP doesn’t know what X() is - This tells me that somehow X() needs to be unevaluated, but still allow for item inserts, which is what the likes of name expr() and expr() are supposed to do, but they don’t work in this case
The example script contains a simplified example of what I want to accomplish. The titles and numbers in the newly generated table are to be inserted into the table script, before the function is run to be inserted into Big Class. I have a basic example of this at the bottom of the script.
Names default to here(1);
clear log();
// Reference table
// Used to populate data in table script below for dt( big )
dt = New Table( "Example",
Add Rows(2),
New Column( "Growth Label", Character, Nominal, Set Values( { "Tall", "Short" } ) ),
New Column( "Height tag", Numeric, Continuous, Set Values( { 67.5, 60 } ) ),
);
// Example table
big = open( "$SAMPLE_DATA/Big Class.jmp" );
// Plain example - vis added as table script * works *
big << New Script( "Example",
Graph Builder(
Size( 534, 456 ),
Show Control Panel( 0 ),
Fit to Window,
Set α Level( 0.05 ),
Variables( X( :weight ), X( :age ), Y( :height ), Color( :sex ) ),
Elements( Points( X, Y, Legend( 4 ) ) ),
SendToReport(
Dispatch(
{},
"height",
ScaleBox,
{Add Ref Line( 67.5, "Dashed", "Medium Dark Green", "Tall", 1 ),
Add Ref Line( 60, "Dashed", "Medium Dark Red", "Short", 1 )}
)
)
)
);
// Needed info for below
vis_x = { :weight, :age };
vis_y = { :height };
// Modified example - vis added as table script * not working *
big << New Script( "Example",
Graph Builder(
Size( 534, 456 ),
Show Control Panel( 0 ),
Fit to Window,
Set α Level( 0.05 ),
Variables( X( vis_x[1] ), X( vis_x[1] ), Y( vis_y[1] ), Color( :sex ) ),
Elements( Points( X, Y, Legend( 4 ) ) ),
SendToReport(
Dispatch(
{},
"height",
ScaleBox,
{Add Ref Line( big:Height tag[1], "Dashed", "Medium Dark Green", big:Growth Label[1], 1 ),
Add Ref Line( big:Height tag[2], "Dashed", "Medium Dark Red", big:Growth Label[2], 1 )}
)
)
)
);
// Example: expression manipulations
var1 = 10; // represents some reference number, from somewhere
var2 = 1; // represents some reference number, from somewhere
expr_test = eval expr( expr(var1) + expr(var2) );
expr_begin = expr( New Script( "Var replacement" ) );
insert into( expr_begin, name expr( expr_test ) );
show( expr_begin );
eval( eval expr( big << expr( name expr( expr_begin ) ) ) ); // Script contains: 10 + 1
/* Notice how the table script "Var replacement" in big doesn't contain var1 & var2,
it contains the values they represent. This is what I want to do. */
close( dt, "No Save" );Searching for "reference lines" yields quite a few results in the community forums. The closest example I have found, so far, are the links below.
https://community.jmp.com/t5/Discussions/Is-there-a-way-to-automatically-draw-ref-lines-at-the-peak-of/m-p/87721/highlight/false#M38710
https://community.jmp.com/t5/Discussions/Fill-color-for-multiple-reference-lines/m-p/273205