cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Browse apps to extend the software in the new JMP Marketplace
Choose Language Hide Translation Bar
Georg
Level VII

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();


Georg
2 ACCEPTED SOLUTIONS

Accepted Solutions
txnelson
Super User

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

txnelson_0-1722946079897.png

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" )} );
Jim

View solution in original post

Re: Taylor Graph Builder expression

@Georg 

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 ) ) )
);
-Scott

View solution in original post

6 REPLIES 6
txnelson
Super User

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();
Jim
Georg
Level VII

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,

 

Georg
txnelson
Super User

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

txnelson_0-1722946079897.png

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" )} );
Jim

Re: Taylor Graph Builder expression

@Georg 

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 ) ) )
);
-Scott
Georg
Level VII

Re: Taylor Graph Builder expression

Thanks to all, that looks good!

Georg
jthi
Super User

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);
-Jarmo