Subscribe Bookmark RSS Feed

Changing Row Legend by Variable

chemistjones

New Contributor

Joined:

Jun 22, 2016

I'm trying to automate a few bivariate plots but I'm running into an issue trying to change the row legends. 

Here is an example of what I'm trying to do:

 

Open("$SAMPLE_DATA/Big Class.jmp");
variables = {"age", "sex"};

for(v=1,v<=nitems(variables),v++,
::var = variables[v];

biv = Bivariate( Y( :height), X( :weight), 
group by(as column(::var)),
	Fit Spline( 1, Standardized, {Line Width( 2 )} ));
	
Report( biv )[Frame Box(1)] << Row Legend( ::var, color(1), marker(1));
);

  My expected output would be two windows with identical plots - one with a spline fit and legend for age and another with a spline fit legend for sex. The spline fits are working as expected, but the row legend command is not recognizing my variable. What am I missing?

 

Thanks in advance!

4 REPLIES
txnelson

Super User

Joined:

Jun 22, 2012

You just need to Eval() the ::Var variable

Open("$SAMPLE_DATA/Big Class.jmp");
variables = {"age", "sex"};

for(v=1,v<=nitems(variables),v++,
::var = variables[v];

biv = Bivariate( Y( :height), X( :weight), 
group by(as column(::var)),
	Fit Spline( 1, Standardized, {Line Width( 2 )} ));
	
Report( biv )[Frame Box(1)] << Row Legend( eval(::var), color(1), marker(1));
);
Jim
chemistjones

New Contributor

Joined:

Jun 22, 2016

Thank you!

Secondary question to help me understand variable evaluation - why does the spline fit work without eval();? When do you need to evaluate the variable and when does it not need evaluated?

txnelson

Super User

Joined:

Jun 22, 2012

The reason for the difference is because requirements of the 2 different statements.  The Fit Spline you mention doesn't have a variable reference, so I assume you are actually questioning why the Group By doesn't need an Eval().  The reasoning is the make up of the requirements for the Group By and the Row Legend.  The Group By is a very simple statement, that has very limited flexability.  It knows that one has to be specifying a column.  In fact, the code will run very nicely even without the As Column() function.  Turning to the Row Legend, this element can take on many different formats and without the Eval() the parser will try to use the actual string of ::var as part of the information, and ::var is not what you vant parsed, the value of ::var is what you want parsed. 

Jim
chemistjones

New Contributor

Joined:

Jun 22, 2016

Very helpful explanation. Thank you!