- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Taylor Graph Builder expression
Dear Community,
I would like to make a Graph Builder Script (want to put that as script in a new table) that contains a long list of y vars.
My first approach was to try expression manipulation, but this did not work as expected.
Can anyone please explain what would be a good way to write that script?
The example below also contains my current way, creating the GB instance, and adding y vars afterwards.
Thanks and best regards,
Names Default To Here( 1 );
cdt = Open( "$SAMPLE_DATA\Big Class.jmp" );
col_lst = cdt << get column names( Continuous, "String" );
gb_expr = Expr(
cdt << Graph Builder(
Size( 534, 450 ),
Show Control Panel( 0 ),
Variables( X( :age ), Y( :height ) ),
Elements( Position( 1, 1 ), Points( X, Y, Legend( 4 ) ) ),
Elements( Position( 1, 2 ), Points( X, Y, Legend( 5 ) ) )
)
);
// this does not work, Expr() does not accept comma separated items
// Substitute Into( gb_expr, Expr( Y( :height ) ), Expr( Y( :height ), Y( :weight ) ) );
// gb_obj = gb_expr;
// this works
// creating GB instance
gb_obj = cdt << Graph Builder(
Size( 534, 450 ),
Show Control Panel( 0 ),
Variables( X( :age )),
Elements( Position( 1, 1 ), Points( X, Y, Legend( 4 ) ) ),
Elements( Position( 1, 2 ), Points( X, Y, Legend( 5 ) ) )
);
// adding Y's
For Each( {ycol}, col_lst, Eval( Parse( Eval Insert( "gb_obj << variables( Y(:^ycol^ ))" ) ) ) );
// this I would like to create directly, w/o large parse/eval parts, that are bad for maintenance
my_target_expression = gb_obj << get script();
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Taylor Graph Builder expression
I am not aware of how to get around the Substitute issue. You may want to explore the Scripting Index Graph Builder messages that can be passed to Graph Builder
Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
gb = Graph Builder(
Variables( X( :sex ) ),
Elements( Points( X, Y ), Smoother( X, Y ) )
);
gb << Add Variable( {:height, Role( "Y" )} );
gb << Add Variable( {:weight, Role( "Y" )} );
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Taylor Graph Builder expression
Building on @txnelson's suggestion about sending messages to graph builder, this might get you closer to what you are looking for:
Names Default To Here( 1 );
cdt = Open( "$SAMPLE_DATA/Big Class.jmp" );
col_lst = cdt << get column names( Continuous, "String" );
gb = Graph Builder(
Variables( X( :age ) ),
Elements( Points( X, Y ) )
);
for each( { yCol }, col_lst,
gb << Add Variable( { eval( yCol ), Role( "Y" ) } );
);
The resulting graph builder script is:
Graph Builder(Variables( X( :age ), Y( :height ), Y( :weight ) ),Elements( Position( 1, 1 ), Points( X, Y, Legend( 1 ) ) ),Elements( Position( 1, 2 ), Points( X, Y, Legend( 2 ) ) ));
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Taylor Graph Builder expression
Might this minor change to use Eval(Eval Expr()) provide you with what you want
Names Default To Here( 1 );
cdt = Open( "$SAMPLE_DATA\Big Class.jmp" );
col_lst = cdt << get column names( Continuous, "String" );
gb_expr = Expr(
cdt << Graph Builder(
Size( 534, 450 ),
Show Control Panel( 0 ),
Variables( X( :age ), Y( :height ) ),
Elements( Position( 1, 1 ), Points( X, Y, Legend( 4 ) ) ),
Elements( Position( 1, 2 ), Points( X, Y, Legend( 5 ) ) )
)
);
// this does not work, Expr() does not accept comma separated items
// Substitute Into( gb_expr, Expr( Y( :height ) ), Expr( Y( :height ), Y( :weight ) ) );
// gb_obj = gb_expr;
// this works
// creating GB instance
gb_obj = cdt << Graph Builder(
Size( 534, 450 ),
Show Control Panel( 0 ),
Variables( X( :age ) ),
Elements( Position( 1, 1 ), Points( X, Y, Legend( 4 ) ) ),
Elements( Position( 1, 2 ), Points( X, Y, Legend( 5 ) ) )
);
// adding Y's
For Each( {ycol}, col_lst,
Eval( Eval Expr( gb_obj << variables( Y( Expr( ycol ) ) ) ) )
);
// this I would like to create directly, w/o large parse/eval parts, that are bad for maintenance
my_target_expression = gb_obj << get script();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Taylor Graph Builder expression
Hi Jim,
thanks, this works as well using eval/evalexpr.
But my question was, how could I build that full gb_expr in the upper part,
my showstopper was, that:
Substitute Into( gb_expr, Expr( Y( :height ) ), Expr( Y( :height ), Y( :weight ) ) );
did not work.
So I want to substitute many "Y(:c1), Y(:c2) ..." into the Graph Builder expression using expression manipulation (not string manipulation).
Best regards,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Taylor Graph Builder expression
I am not aware of how to get around the Substitute issue. You may want to explore the Scripting Index Graph Builder messages that can be passed to Graph Builder
Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
gb = Graph Builder(
Variables( X( :sex ) ),
Elements( Points( X, Y ), Smoother( X, Y ) )
);
gb << Add Variable( {:height, Role( "Y" )} );
gb << Add Variable( {:weight, Role( "Y" )} );
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Taylor Graph Builder expression
Building on @txnelson's suggestion about sending messages to graph builder, this might get you closer to what you are looking for:
Names Default To Here( 1 );
cdt = Open( "$SAMPLE_DATA/Big Class.jmp" );
col_lst = cdt << get column names( Continuous, "String" );
gb = Graph Builder(
Variables( X( :age ) ),
Elements( Points( X, Y ) )
);
for each( { yCol }, col_lst,
gb << Add Variable( { eval( yCol ), Role( "Y" ) } );
);
The resulting graph builder script is:
Graph Builder(Variables( X( :age ), Y( :height ), Y( :weight ) ),Elements( Position( 1, 1 ), Points( X, Y, Legend( 1 ) ) ),Elements( Position( 1, 2 ), Points( X, Y, Legend( 2 ) ) ));
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Taylor Graph Builder expression
Thanks to all, that looks good!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Taylor Graph Builder expression
I don't usually use substitute for that but rather build them using expressions, below is one option but there are other options
Names Default To Here(1);
dt = Open("$SAMPLE_DATA\Big Class.jmp");
col_lst = cdt << get column names(Continuous, "String");
var_expr = Expr(Variables(X(:age)));
For Each({colname}, col_lst,
colname = "height";
Insert Into(var_expr, EvalExpr(Y(Expr(Name Expr(As Column(dt, colname))))));
);
gb_expr = EvalExpr(
dt << Graph Builder(
Size(534, 450),
Show Control Panel(0),
Expr(Name Expr(var_expr))
);
);
gb = Eval(gb_expr);
// gb << get script
gb << Save Script to Data Table("Plot");
If you just want to use Substitute, I think you will have to substitute the whole Variables part (or possibly do some tricks)
Names Default To Here(1);
cdt = Open("$SAMPLE_DATA\Big Class.jmp");
col_lst = cdt << get column names(Continuous, "String");
gb_expr = Expr(
cdt << Graph Builder(
Size(534, 450),
Show Control Panel(0),
Variables(X(:age), Y(:height)),
Elements(Position(1, 1), Points(X, Y, Legend(4))),
Elements(Position(1, 2), Points(X, Y, Legend(5)))
)
);
Substitute Into(gb_expr, Expr(Variables(X(:age), Y(:height))), Expr(Variables(X(:age), Y(:height), Y(:weight))));
show(gb_expr);