cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Try the Materials Informatics Toolkit, which is designed to easily handle SMILES data. This and other helpful add-ins are available in the JMP® Marketplace
Choose Language Hide Translation Bar

How to loop through the unique values of a column to fit a line in a bivariate plot?

I am trying to write a jsl to plot a bivariate plot between x vs. y, group by the values in column 'b' and fit a line through each of the groups (from the unique values in column 'b'). The script generated from the manual bivariate plot I did is as follows but I cannot figure out how to do add a for loop for all the "Fit Where" commands that go through the unique values in column 'b'

Bivariate(
	Y( :Name( "y" ) ),
	X( :Name( "x" ) ),
	Automatic Recalc( 1 ),
	Fit Where(  == "grpA", Fit Line( {Line Color( {228, 26, 28} )} ) ),
	Fit Where(
		:b == "grpB",
		Fit Line( {Line Color( {55, 126, 184} )} )
	),
	Fit Where(
		:b == "grpC",
		Fit Line( {Line Color( {77, 175, 74} )} )
	),
	Fit Where(
		:b == "grpD",
		Fit Line( {Line Color( {152, 78, 163} )} )
	),
	Fit Where(
		:b == "grpE",
		Fit Line( {Line Color( {255, 127, 0} )} )
	),
	Fit Where(
		:b == "grpF",
		Fit Line( {Line Color( {166, 86, 40} )} )
	),
	Where( :c == "TT" & :e == "EE" ),
	SendToReport(
		Dispatch( {}, "1", ScaleBox, {Reversed Scale} ),
		Dispatch( {}, "2", ScaleBox, {Reversed Scale} ),
		Dispatch(
			{},
			"Bivar Plot",
			FrameBox,
			{Marker Size( 6 ), Row Legend(
				e,
				Color( 0 ),
				Color Theme( "" ),
				Marker( 1 ),
				Marker Theme( "Standard" ),
				Continuous Scale( 0 ),
				Reverse Scale( 0 ),
				Excluded Rows( 0 )
			)}
		),
		Dispatch( {}, "Linear Fit b==grpA, OutlineBox, {Close( 1 )} ),
		Dispatch( {}, "Linear Fit b==grpB", OutlineBox, {Close( 1 )} ),
		Dispatch(
			{},
			"Linear Fit b==grpC",
			OutlineBox,
			{Close( 1 )}
		),
		Dispatch(
			{},
			"Linear Fit b==grpD",
			OutlineBox,
			{Close( 1 )}
		),
		Dispatch(
			{},
			"Linear Fit b==grpE",
			OutlineBox,
			{Close( 1 )}
		),
		Dispatch(
			{},
			"Linear Fit b==grpF",
			OutlineBox,
			{Close( 1 )}
		)
	)
);
3 REPLIES 3
txnelson
Super User

Re: How to loop through the unique values of a column to fit a line in a bivariate plot?

I believe it will be easier to set the colors in a Column Property for variable :b, and to use a By() element.

names default to here(1);

:b << set property("value colors",
	{"grp8" = {55, 126, 184} }, "grpC" = {77, 175, 74}  etc. }
);
Bivariate(
	Y( :x ),
	X( :y ),
	Fit Line( ),
by( : B ) );
Jim
vince_faller
Super User (Alumni)

Re: How to loop through the unique values of a column to fit a line in a bivariate plot?

I think what you're looking for is the groupby() arg.  If you want to specify colors, definitely it's easier to do at the column level like @txnelson said.  

 

Names default to here( 1 );
dt = open("$SAMPLE_DATA\Big Class.jmp");
biv = dt << Bivariate(
	Y( :weight ),
	X( :height ),
	Group BY(:sex), 
	Fit line()
);
Vince Faller - Predictum

Re: How to loop through the unique values of a column to fit a line in a bivariate plot?

The Bivariate platform has its own Group By feature available from the platform menu or JSL:

 

Names Default to Here( 1 );

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

obj = dt << Bivariate(
	Y( :weight ),
	X( :height )
);

obj
	<< Group By( :sex )
	<< Fit Line;