cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • Instantly extract effect sizes, F-ratios, and FDR-adjusted p-values from your models with the Calculate Effects Sizes extension, available now in the JMP Marketplace!
  • New to JMP? Join us Sept. 23-24 for the Early User Edition of Discovery Summit, tailor-made for new users. Register now for free!
  • Your voice matters! Tell us how you prefer to receive JMP updates, so we can tailor our communication to your needs. Take short survey.

Discussions

Solve problems, and share tips and tricks with other JMP users.
Choose Language Hide Translation Bar
AdamChoen
Level IV

Dynamic Y variables in Graph Builder from user selection

Hello,

I’m trying to dynamically control multiple Y axes in Graph Builder based on a user Check Box selection.

Hard-coded Y variables work fine, but any dynamic construction fails (Y unresolved, ignored, or empty plot).

I’ve tried:

  • Add Variable( Y(...) )

  • building Expr( Y( ... ) ) lists

  • Eval / Expr / Column() combinations
    (as suggested in existing forum threads)

None work for me.

 

 

  • Dynamic number of Y variables (1–4)

  • Each Y has independent limits / ref lines

  • Cannot stack data

  • Must use Graph Builder

 

 

// Does NOT work 

dt = Open( "$SAMPLE_DATA/Big Class.jmp" );

// Simulate user selection
Chosen_Ys_list = {"height", "weight"};

// Attempt to build Y list dynamically
Y_List = {};
For( i = 1, i <= N Items( Chosen_Ys_list ), i++,
    Insert Into( Y_List, Expr( Y( Eval( Chosen_Ys_list[i] ) ) ) );
);


dt << Graph Builder(
    Variables(
        X( :age ),
        Eval( Y_List )   // <- ignored or errors
    )
);


// 2nd try
gb = dt << Graph Builder(
    Variables( X( :age ) )
);

gb << Add Variable( Y( :height ) );  // Name Unresolved: Y

 

 

Thanks, Adam
2 ACCEPTED SOLUTIONS

Accepted Solutions
jthi
Super User

Re: Dynamic Y variables in Graph Builder from user selection

For << Add Variable you can find the correct syntax from Scripting Index

jthi_0-1766500033326.png

 

Not sure what the final plot is supposed to look like, so here is only one simple example using << Add Variable

Names Default To Here(1);

dt = Open("$SAMPLE_DATA/Big Class.jmp");

cols = {"height", "weight"};

gb = dt << Graph Builder(Variables(X(:age)));
For Each({colname}, cols,
	Eval(EvalExpr(
		gb << Add Variable({Expr(Name Expr(AsColumn(dt, colname))), Role("Y")})
	));
);

jthi_1-1766500130433.png

 

-Jarmo

View solution in original post

hogi
Level XIII

Re: Dynamic Y variables in Graph Builder from user selection

There is an issue with your Y_List:

hogi_0-1766525871748.png

besides that, you will run into issues with the "List".

As an alternative to Add Variable (), you can start with a variable_expr, add more variables, and then use it in the Graph Builder command.

Independent of the approach, the correct  positioning  of Eval , Eval Expr, Expr, and NameExpr in the code is essential.
the details can be found in the documentation
... and in some community posts
https://www.google.com/search?q=expression+handling++site%3Acommunity.jmp.com 

Variables_Expr  = Expr(Variables (X(:age)));

For( i = 1, i <= N Items( Chosen_Ys_list ), i++,
    Insert Into( Variables_Expr, Eval Expr( Y( Expr(Name Expr(As Column( Chosen_Ys_list[i] ) ) ) );
)));


Eval (Eval Expr(dt << Graph Builder(
        Expr(Name Expr(( Variables_Expr ) ))    
)));

View solution in original post

2 REPLIES 2
jthi
Super User

Re: Dynamic Y variables in Graph Builder from user selection

For << Add Variable you can find the correct syntax from Scripting Index

jthi_0-1766500033326.png

 

Not sure what the final plot is supposed to look like, so here is only one simple example using << Add Variable

Names Default To Here(1);

dt = Open("$SAMPLE_DATA/Big Class.jmp");

cols = {"height", "weight"};

gb = dt << Graph Builder(Variables(X(:age)));
For Each({colname}, cols,
	Eval(EvalExpr(
		gb << Add Variable({Expr(Name Expr(AsColumn(dt, colname))), Role("Y")})
	));
);

jthi_1-1766500130433.png

 

-Jarmo
hogi
Level XIII

Re: Dynamic Y variables in Graph Builder from user selection

There is an issue with your Y_List:

hogi_0-1766525871748.png

besides that, you will run into issues with the "List".

As an alternative to Add Variable (), you can start with a variable_expr, add more variables, and then use it in the Graph Builder command.

Independent of the approach, the correct  positioning  of Eval , Eval Expr, Expr, and NameExpr in the code is essential.
the details can be found in the documentation
... and in some community posts
https://www.google.com/search?q=expression+handling++site%3Acommunity.jmp.com 

Variables_Expr  = Expr(Variables (X(:age)));

For( i = 1, i <= N Items( Chosen_Ys_list ), i++,
    Insert Into( Variables_Expr, Eval Expr( Y( Expr(Name Expr(As Column( Chosen_Ys_list[i] ) ) ) );
)));


Eval (Eval Expr(dt << Graph Builder(
        Expr(Name Expr(( Variables_Expr ) ))    
)));

Recommended Articles