- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
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.
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
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] ) || "\!")" )
)
)
);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
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] ) || "\!")" )
)
)
);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Creating Plots in a For Loop
Thanks for the help! I got the script working!