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
Rajat
Level IV

For loop Graph builder with reference line

Hi, 

I want to write a script with for loop to generate Box plots with horizontal refernce lines and save it. I can do it in graph builder also but my dataset is huge so adding refernce line manually would take too much tim.

I have to two data table one to generate data table and other to generate refernce lines.

 

I want to have a loop to Box plot Player (in this case 'a' and 'b) on X-axis and column would switches for all games ('Badminton', 'Table Tennis', 'Lawn Tennis'). JMP script would also read one more file that contains refernce line and overlay refernce lines of particular game to that particular plot.

Please help to write a script for this requirement.

Thanks :) 

 

GameRefernce Line 1Refernce Line 2
Badminton71
Table Tennis82
Lawn Tennis63

 

PlayerZoneBadmintonTable TennisLawn Tennis
aNorth223
aNorth363
aNorth465
aNorth522
aNorth256
aNorth456
aNorth436
aNorth452
aNorth976
aNorth505
bSouth137
bSouth247
bSouth478
bSouth363
bSouth645
bSouth222
bSouth586
bSouth652
bSouth723
bSouth646

 

1 ACCEPTED SOLUTION

Accepted Solutions
txnelson
Super User

Re: For loop Graph builder with reference line

Then a different approach would have to be used.  Response Limits only support Lower, Middle and Upper.

Here is a simple script that works with the data tables you supplied, that will plot out all of the reference lines

Names Default To Here( 1 );
dtMain = Data Table( "Main" );
dtLimits = Data Table( "Limits" );

// Get the columns to create box plots for
boxPlotList = dtMain << get column names( string, numeric );

// Get the columns that contain limits
refLineList = dtLimits << get column names( string, numeric );

// Loop across the box plot columns and generate the box plots
For( i = 1, i <= N Items( boxPlotList ), i++, 
	ow = Oneway( Y( Column( boxPlotList[i] ) ), X( :Player ), Box Plots( 1 ) );
	
	// Find out if any reference line references are specified for the current
	// box plot column
	refLineMatrix = dtLimits << get rows where( :game == boxPlotList[i] );
	
	// If references are found, then loop across the columns and rows in the Limits table
	// and add the reference lines
	If( N Rows( refLineMatrix ) > 0,
		For( refRow = 1, refRow <= N Rows( refLineMatrix ), refRow++,
			For( refCol = 1, refCol <= N Items( refLineList ), refCol++,
				refLineValue = Column( dtLimits, refLineList[refCol] )[refRow];
				Report( ow )[AxisBox( 1 )] << Add Ref Line( refLineValue, "Solid", "Black", "", 1 );
			)
		)
	);
);
Jim

View solution in original post

5 REPLIES 5
txnelson
Super User

Re: For loop Graph builder with reference line

I suggest that you just enter the values from your second data table as a "Response Limits" column property.  If you do that, they will be displayed on the charts you are using automatically.

response.PNG

 

Jim
Rajat
Level IV

Re: For loop Graph builder with reference line

I didin't get how actually I will do add the data from second table as response limit.

Also, I have 2293 columns like that and this activity I have to do every week. So, its better to have ascript.

txnelson
Super User

Re: For loop Graph builder with reference line

Here is a script that first creates the 2 data tables you displayed in your first entry, followed by the code that copies the limits from the limits table and applies them to each column in the main table

Names Default To Here( 1 );

dtMain = New Table( "Main",
	Add Rows( 20 ),
	New Column( "Player",
		Character,
		"Nominal",
		Set Values(
			{"a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "b", "b", "b", "b", "b", "b", "b", "b", "b", "b"}
		)
	),
	New Column( "Zone",
		Character,
		"Nominal",
		Set Values(
			{"North", "North", "North", "North", "North", "North", "North", "North", "North", "North", "South",
			"South", "South", "South", "South", "South", "South", "South", "South", "South"}
		)
	),
	New Column( "Badminton",
		Numeric,
		"Continuous",
		Format( "Best", 12 ),
		Set Values( [2, 3, 4, 5, 2, 4, 4, 4, 9, 5, 1, 2, 4, 3, 6, 2, 5, 6, 7, 6] )
	),
	New Column( "Table Tennis",
		Numeric,
		"Continuous",
		Format( "Best", 12 ),
		Set Values( [2, 6, 6, 2, 5, 5, 3, 5, 7, 0, 3, 4, 7, 6, 4, 2, 8, 5, 2, 4] )
	),
	New Column( "Lawn Tennis",
		Numeric,
		"Continuous",
		Format( "Best", 12 ),
		Set Values( [3, 3, 5, 2, 6, 6, 6, 2, 6, 5, 7, 7, 8, 3, 5, 2, 6, 2, 3, 6] )
	)
);
dtLimits = New Table( "Limits",
	Add Rows( 3 ),
	New Column( "Game",
		Character,
		"Nominal",
		Set Values( {"Badminton", "Table Tennis", "Lawn Tennis"} ),
		Set Display Width( 128 )
	),
	New Column( "Reference Line 1", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [7, 8, 6] ) ),
	New Column( "Reference Line 2", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [1, 2, 3] ) )
);


// Here is the code that sets the Response Limits
For( i = 1, i <= N Rows( dtLimits ), i++,
	If( Try( (Column( dtMain, (Column( dtLimits, "Game" )[i]) )) << get name, "" ) != "", 

		Eval(
			Substitute(
					Expr(
						Column( dtMain, Column( dtLimits, "Game" )[i] ) << set property(
							"response limits",
							{Goal( Maximize ), Lower( __Low__, 1 ), Upper( __up__, 1 ), Importance( 1 ),
							Show Limits( 1 )}
						)
					),
				Expr( __Low__ ), dtLimits:Reference Line 2[i],
				Expr( __Up__ ),
					dtLimits:Reference Line 1[i]
			)
		)
	)
);
Jim
Rajat
Level IV

Re: For loop Graph builder with reference line

If I want to put 5 reference limits then what I have to change?
txnelson
Super User

Re: For loop Graph builder with reference line

Then a different approach would have to be used.  Response Limits only support Lower, Middle and Upper.

Here is a simple script that works with the data tables you supplied, that will plot out all of the reference lines

Names Default To Here( 1 );
dtMain = Data Table( "Main" );
dtLimits = Data Table( "Limits" );

// Get the columns to create box plots for
boxPlotList = dtMain << get column names( string, numeric );

// Get the columns that contain limits
refLineList = dtLimits << get column names( string, numeric );

// Loop across the box plot columns and generate the box plots
For( i = 1, i <= N Items( boxPlotList ), i++, 
	ow = Oneway( Y( Column( boxPlotList[i] ) ), X( :Player ), Box Plots( 1 ) );
	
	// Find out if any reference line references are specified for the current
	// box plot column
	refLineMatrix = dtLimits << get rows where( :game == boxPlotList[i] );
	
	// If references are found, then loop across the columns and rows in the Limits table
	// and add the reference lines
	If( N Rows( refLineMatrix ) > 0,
		For( refRow = 1, refRow <= N Rows( refLineMatrix ), refRow++,
			For( refCol = 1, refCol <= N Items( refLineList ), refCol++,
				refLineValue = Column( dtLimits, refLineList[refCol] )[refRow];
				Report( ow )[AxisBox( 1 )] << Add Ref Line( refLineValue, "Solid", "Black", "", 1 );
			)
		)
	);
);
Jim