cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Submit your abstract to the call for content for Discovery Summit Americas by April 23. Selected abstracts will be presented at Discovery Summit, Oct. 21- 24.
Discovery is online this week, April 16 and 18. Join us for these exciting interactive sessions.
Choose Language Hide Translation Bar
rfeick
Level IV

Creating Plots in a For Loop

I have a script that creates up to eight very similar plots as part of the analysis. The number of plots can vary based on if corresponding columns exist. The only differences in the plots are the columns being used for the y axis data and the titels. In the interest of efficiency I was trying to avoid just scripting each plot sequentially. I tried using a for loop that pulled from pre-established lists of column names and titles, but I couldn't get it to work. Is this actually possible in JMP 13? I've attached the script section of what I tried.

1 ACCEPTED SOLUTION

Accepted Solutions
txnelson
Super User

Re: Creating Plots in a For Loop

A couple of issues.

1. Your Graph Builder code had a missplaced ")" which was ending the code with a parsing error.

2. The :Name() function does not resolve elements, so you can not have something like: cols[f] as a value for the function.  It needs to be passed just a quoted string,

The code below fixes both issues

For( f = 1, f <= N Items( plots ), f++,
	Eval(
		Substitute(
				Expr(
					__plots__ = Graph Builder(
						Size( 1267, 905 ),
						Show Control Panel( 0 ),
						Show Legend( 0 ),
						Variables( X( :RPN, Order By( __col__ ), Descending, Order Statistic( "Mean" ) ) ),
						Y( __col__ ),
						Elements( Bar( X, Y, Legend( 4 ), Label( "Label by Value" ) ) ),
						SendToReport(
							Dispatch( {}, "Graph Builder", OutlineBox, {Set Title( outline titles[f] )} ),
							Dispatch( {}, "RPN", ScaleBox, {Max( 10.5 ), Label Row( Label Orientation( "Angled" ) )} ),
							Dispatch( {}, "400", ScaleBox, {Legend Model( 4, Properties( 0, {Fill Color( 53 )} ) )} ),
							Dispatch( {}, "graph title", TextEditBox, {Set Text( plot titles[f] )} ),
							Dispatch( {}, "X title", TextEditBox, {Set Text( "RPN" )} ),
							Dispatch( {}, "Y title", TextEditBox, {Set Text( "Affected Lots" )} ),
							Dispatch( {}, "400", LegendBox, {Set Title( "" )} )
						)
					)
				),
			Expr( __plots__ ), Parse( "Plots" || Char( f ) ),
			Expr( __col__ ), Parse( ":Name(\!"" || Char( cols[f] ) || "\!")" )
		)
	)
);
Jim

View solution in original post

2 REPLIES 2
txnelson
Super User

Re: Creating Plots in a For Loop

A couple of issues.

1. Your Graph Builder code had a missplaced ")" which was ending the code with a parsing error.

2. The :Name() function does not resolve elements, so you can not have something like: cols[f] as a value for the function.  It needs to be passed just a quoted string,

The code below fixes both issues

For( f = 1, f <= N Items( plots ), f++,
	Eval(
		Substitute(
				Expr(
					__plots__ = Graph Builder(
						Size( 1267, 905 ),
						Show Control Panel( 0 ),
						Show Legend( 0 ),
						Variables( X( :RPN, Order By( __col__ ), Descending, Order Statistic( "Mean" ) ) ),
						Y( __col__ ),
						Elements( Bar( X, Y, Legend( 4 ), Label( "Label by Value" ) ) ),
						SendToReport(
							Dispatch( {}, "Graph Builder", OutlineBox, {Set Title( outline titles[f] )} ),
							Dispatch( {}, "RPN", ScaleBox, {Max( 10.5 ), Label Row( Label Orientation( "Angled" ) )} ),
							Dispatch( {}, "400", ScaleBox, {Legend Model( 4, Properties( 0, {Fill Color( 53 )} ) )} ),
							Dispatch( {}, "graph title", TextEditBox, {Set Text( plot titles[f] )} ),
							Dispatch( {}, "X title", TextEditBox, {Set Text( "RPN" )} ),
							Dispatch( {}, "Y title", TextEditBox, {Set Text( "Affected Lots" )} ),
							Dispatch( {}, "400", LegendBox, {Set Title( "" )} )
						)
					)
				),
			Expr( __plots__ ), Parse( "Plots" || Char( f ) ),
			Expr( __col__ ), Parse( ":Name(\!"" || Char( cols[f] ) || "\!")" )
		)
	)
);
Jim
rfeick
Level IV

Re: Creating Plots in a For Loop

Thanks for the help! I got the script working!