cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Check out the JMP® Marketplace featured Capability Explorer add-in
Choose Language Hide Translation Bar
shiro
Level I

fit a spline with a variable

Hey,

I build a chart with dinamic legend that the user can choose by radio box.

The name of the legend that the user choose is saved as 'L1' variable.

I want to add a function that when a user clicks on one value from the legend the spline of this value become more bold.

I add a state handler to the file and tried to use this script:

 

rsh1 = test1 << Make Row State Handler( dt, rsupdate1 );

rsupdate1 =function({},
SplineSelectlist=dt:L1[dt<<get selected rows];
SplineSelect=SplineSelectlist[1];
// MYSPLINE=EVAL(SplineSelect);
box8<<Fit Where(
:eval(L1) == eval(SplineSelect),
Fit Spline(
0.1,
Standardized,
{Line Width( 5 )}
));
);

 

The 'fit where' state doesnt recognize the variable.

I also tried with 'parse' or without 'eval' or to define the variable before-

mycolumn= eval(L1);

but none of them work.

 

I will be glad to hear if there's a solution to this.

 Thank you.

4 REPLIES 4
gzmorgan0
Super User (Alumni)

Re: fit a spline with a variable

There is not enough information here to respond, and there are some syntax issues.

 

Does the graph have splines already drawn and you want the selected item highlighted?

Are you using GraphBuilder or Bivariate (Fit Y by X)?

 

:eval(L1) is not proper syntax.

 

 

 

gzmorgan0
Super User (Alumni)

Re: fit a spline with a variable

Since no more information was provided, I am guessing at what you need. Maybe you only needed to make your spline statement using and expresssion.   This script allows one or multiple legend values to be selected. It uses:

  • The default linking of an invisible summary table to manage legend selections. This invisible table is closed when the bivariate is closed.
  • A rowstate handler function to clear out previous splines and only show those selected from the legend. 
  • It's been tested on JMP14.1 and JMP13.21.

 

image.png

Names Default to Here(1);

dt0 = Open("$sample_data/SATByYear.jmp");

//create a smaller table too many groupings
dt0 << Select Where( :Region=="Plains" | :Region=="South");
dt = dt0 << Subset(All Columns, Output Tablename("SomeStates"));

close(dt0,NoSave);  

//change Year from Ordinal to Continuous to create a Bivariate report
dt:Year << Set Modeling Type("Continuous");  

//The legend column is hardcoded. It seemed like you know how to do that.
//I created a new column just for interest
gCol = dt << New Column("Region_State", character);
gcol << set each value( substr(:Region,1,1) || "_" || :State);
dt << Color by Column(:Region);

//Create the Bivariate report
biv = dt <<  Bivariate( Y(:SAT Math), X(:Year) );
//Add a row legion for the legend column. For your script you woudl have to remove the
//previous legend and add a new one.
rbiv = Report(biv);
fb = rbiv[FrameBox(1)];

//You would likely change both color and symbol, just made it different for interest
fb << Row Legend(:Region_State, color(0), Marker(1));

//It will be easier to create the Spline with a By group. The Summary table simplifies the task. 
sumdt =dt << Summary(Group(:Region_State), Invisible);
//if the biv winow is closed/ close summary table
biv << On Close (Close(sumdt, NoSave)); //closes the summary table and row state handler

//Create a row state handler function, that defines the tasks when rge rowstate of sumdt changes. 
f = Function({a},
	_c = biv << Xpath("//IfBox[@isTrue='true']");
    for(i=nitems(_c), i>=1, i--,  biv << (curve[i] << Remove Fit) ); 
    _yy = sumdt << get selected rows();
    if(nrow(_yy)>0,
       _xx = (sumdt:Region_State<<get values)[_yy];
       _zz = (sumdt <<get rowstates )[_yy];
	   for(i = 1, i<=nitems(_xx), i++,
	   _clr = Color to RGB(ColorOf(AsRowState(_zz[i])));
	   //show(_yy[i], _xx[i], _zz[i], _clr[i] );
	   Eval(EvalExpr(biv << Fit Where(Expr(gcol)[]==Expr(_xx[i]), Fit Spline(0.1, Standardized,
            {Line Color(Expr(_clr) ), Line Width( 5 )}) ) ) );
       );
    );
);

rs = sumdt<<Make Row State Handler(f);
//Use Ctrl+ click to deselect or select multiple states [processes] 

 

vsr
vsr
Level I

Re: fit a spline with a variable

Hello, 

I'd like to join in on the initial querry, since I've encountered a similar problem. 

I am trying to create a "legand chooser button" where each value is a column name.

when choosing a value, the leagend and spline of my Bivariate x/y graph will be updated according to the chosen value (the previous legend and the spline will be erased).

However, I don't know how to adapt the "fit where" function to recive a variable as input (the variable being the selected column name), as is described in the original query here.

Thanks, Hadar

gzmorgan0
Super User (Alumni)

Re: fit a spline with a variable

@vsr, your task is different from @shiro's task. @shiro needed to fit a spline by different values of one column.

 

Look at the example I provided, the curve shown is is different for different values of :State.

 

From your description, you seem to want different columns, not different values of one column. Fit Where is selecting on values of a chosen column. Without more details of what specifically you are trying to do, I can only guess.

 

My guess is that you might want to plot different Y's or different X's, that is columns. If that is teh case JMP has a builtin solution, called a column switcher.  Just in case, that is what you are needing, I provided an example screenshot and script.  If this is not what you need, please provide more details.

 

image.png

 

Names Default to Here(1);

dt = Open("$sample_data/TechStock.jmp");

biv = dt << Bivariate(
	Y( :Name( "Adj. Close*" ) ),
	X( :Date ),
	Fit Spline( 10, {Line Color( {212, 73, 88} )} ),
	Column Switcher(
		:Name( "Adj. Close*" ),
		{:Open, :High, :Low, :Close, :Name( "Adj. Close*" )}
	)
);
//select a Y column one at a time or select the "play/go" button and JMP will cycle thru all columns