Choose Language Hide Translation Bar
Highlighted
LBrian
Level II

Can you help to make multiple scatterplots into a table using script?

Hello, All.

 

I can print a multiple scatterplots into a table using this script which I made.

 

Names Default To Here( 1 );
dt = Open( "$Sample_Data/Big Class.jmp" );
dt = Current Data Table();

For( i = 4, i <= N Cols( dt ), i++,
	Column( dt, i ) << data type( numeric );
	Column( dt, i ) << set modeling type( continuous );
);
address = Current Data Table();

Scatterplot Matrix(
	Y(
	 :Column(address, 4),
	 :Column(address, 5) 
	 	
	 ),
	X( :Column(address, 2) ),
	Fit Line( 0 ),
	SendToReport
	( 
		Dispatch
		( 
		{}, 
		"1100", 
		ScaleBox, 
					{
					Add Ref Line( :Column(address, 4)[2], "Solid", "Medium Dark Blue", "LSL", 1 ),
					Add Ref Line( :Column(address, 4)[3], "Solid", "Medium Dark Blue", "USL", 1 )
					} 
		),
		Dispatch
		( 
		{}, 
		"1101", 
		ScaleBox, 
					{
					Add Ref Line( :Column(address, 5)[2], "Solid", "Medium Dark Blue", "LSL", 1 ),
					Add Ref Line( :Column(address, 5)[3], "Solid", "Medium Dark Blue", "USL", 1 )
					} 
		),
		 Dispatch(
			{},
			"Scatterplot Matrix Plot",
			FrameBox,
			{Frame Size( 600, 200 )}
		),
	)
);

 

 

I tried to use [for] function like the script below.

 

Names Default To Here( 1 );
dt = Open( "$Sample_Data/Big Class.jmp" );
dt = Current Data Table();

For( i = 4, i <= N Cols( dt ), i++, 
	Column( dt, i ) << data type( numeric );
	Column( dt, i ) << set modeling type( continuous );
);
address = Current Data Table();

For( i = 4, i <= 5, i++,
Scatterplot Matrix(
	Y(
	 :Column(address, i) 
	 ),
	X( :Column(address, 2) ),
	Fit Line( 0 ),
	SendToReport
	( 
		Dispatch
		( 
		{}, 
		"1100", 
		ScaleBox, 
					{
					Add Ref Line( :Column(address, i)[2], "Solid", "Medium Dark Blue", "LSL", 1 ),
					Add Ref Line( :Column(address, i)[3], "Solid", "Medium Dark Blue", "USL", 1 )
					} 
		),

		 Dispatch(
			{},
			"Scatterplot Matrix Plot",
			FrameBox(i),
			{Frame Size( 600, 200 )}
		)
	)
);
);

 

 

 

however, the script made graphs each other.

 

 

Please help me to make a multiple scatter into a table using [for] function... T^T

 

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
txnelson
Super User

Re: Can you help to make multiple scatterplots into a table using script?

Your proposal for where you want to use a For() loop, really isn't what is needed.  If I am understanding you correctly, what you want is to produce a scatterplot matrix with multiple Y columns and a single x column.  To do this, you do not need to loop across the scatterplot code, all you really need to do, is to create a list of columns you want for Y's, and then plug that list in.  Now concerning the adding of spec limits to each of the graphs, I suggest you create an independent table with the required limits, and then to copy the limits into the data table.  then when the data are processed, the limits will automatically be placed on to the various matrices.

Names Default To Here( 1 );
dt = Open( "$Sample_Data/Blood pressure.jmp" );

// Create a list of all of the columns one wants for Y values in the 
// scatterplot matrix
colNamesList = dt << get column names( continuous );

// Here is the limits table.  This can be just a saved data table that is
// opened in the script.  It does not have to be a table built in a script
dtLimits = New Table( "Limits",
	Add Rows( 9 ),
	New Column( "Variable",
		Character,
		"Nominal",
		Set Values( {"BP 8M", "BP 12M", "BP 6M", "BP 8W", "BP 12W", "BP 6W", "BP 8F", "BP 12F", "BP 6F"} )
	),
	New Column( "LSL",
		Numeric,
		"Continuous",
		Format( "Best", 12 ),
		Set Values( [175, 175, 175, 171, 173, 171, 172, 174, 172] )
	),
	New Column( "USL",
		Numeric,
		"Continuous",
		Format( "Best", 12 ),
		Set Values( [180, 185, 185, 187, 190, 180, 185, 188, 186] )
	),
	New Column( "Target", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [., ., ., ., ., ., ., ., .] ) ),
	New Column( "Show Limits",
		Numeric,
		"Nominal",
		Format( "Best", 12 ),
		Set Values( [1, 1, 1, 1, 1, 1, 1, 1, 1] )
	)
);

// Add the limits from the limits data table to the data table with the
// data values in it
For( i = 1, i <= N Rows( dtLimits ), i++,
	Eval(
		Substitute(
				Expr(
					Column( dt, dtLimits:Variable[i] ) << set property(
						"spec limits",
						{LSL( __LSL__ ), USL( __USL__ ), show limits( 1 )}
					)
				),
			Expr( __LSL__ ), dtLimits:LSL[i],
			Expr( __USL__ ), dtLimits:USL[i]
		)
	)
);

// Create the Scatterplot Matrix
dt << Scatterplot Matrix(
	Y(
		Eval( colNamesList ) 
	 	
	),
	X( :Column( dt, 2 ) ),
	Fit Line( 0 ),
	SendToReport( Dispatch( {}, "Scatterplot Matrix Plot", FrameBox, {Frame Size( 600, 200 )} ), )
);



Jim

View solution in original post

2 REPLIES 2
Highlighted
txnelson
Super User

Re: Can you help to make multiple scatterplots into a table using script?

Your proposal for where you want to use a For() loop, really isn't what is needed.  If I am understanding you correctly, what you want is to produce a scatterplot matrix with multiple Y columns and a single x column.  To do this, you do not need to loop across the scatterplot code, all you really need to do, is to create a list of columns you want for Y's, and then plug that list in.  Now concerning the adding of spec limits to each of the graphs, I suggest you create an independent table with the required limits, and then to copy the limits into the data table.  then when the data are processed, the limits will automatically be placed on to the various matrices.

Names Default To Here( 1 );
dt = Open( "$Sample_Data/Blood pressure.jmp" );

// Create a list of all of the columns one wants for Y values in the 
// scatterplot matrix
colNamesList = dt << get column names( continuous );

// Here is the limits table.  This can be just a saved data table that is
// opened in the script.  It does not have to be a table built in a script
dtLimits = New Table( "Limits",
	Add Rows( 9 ),
	New Column( "Variable",
		Character,
		"Nominal",
		Set Values( {"BP 8M", "BP 12M", "BP 6M", "BP 8W", "BP 12W", "BP 6W", "BP 8F", "BP 12F", "BP 6F"} )
	),
	New Column( "LSL",
		Numeric,
		"Continuous",
		Format( "Best", 12 ),
		Set Values( [175, 175, 175, 171, 173, 171, 172, 174, 172] )
	),
	New Column( "USL",
		Numeric,
		"Continuous",
		Format( "Best", 12 ),
		Set Values( [180, 185, 185, 187, 190, 180, 185, 188, 186] )
	),
	New Column( "Target", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [., ., ., ., ., ., ., ., .] ) ),
	New Column( "Show Limits",
		Numeric,
		"Nominal",
		Format( "Best", 12 ),
		Set Values( [1, 1, 1, 1, 1, 1, 1, 1, 1] )
	)
);

// Add the limits from the limits data table to the data table with the
// data values in it
For( i = 1, i <= N Rows( dtLimits ), i++,
	Eval(
		Substitute(
				Expr(
					Column( dt, dtLimits:Variable[i] ) << set property(
						"spec limits",
						{LSL( __LSL__ ), USL( __USL__ ), show limits( 1 )}
					)
				),
			Expr( __LSL__ ), dtLimits:LSL[i],
			Expr( __USL__ ), dtLimits:USL[i]
		)
	)
);

// Create the Scatterplot Matrix
dt << Scatterplot Matrix(
	Y(
		Eval( colNamesList ) 
	 	
	),
	X( :Column( dt, 2 ) ),
	Fit Line( 0 ),
	SendToReport( Dispatch( {}, "Scatterplot Matrix Plot", FrameBox, {Frame Size( 600, 200 )} ), )
);



Jim

View solution in original post

Highlighted
LBrian
Level II

Re: Can you help to make multiple scatterplots into a table using script?

Your advice is very helpful to me.

Thank you, Dr jim!