<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Using a For Loop with X by Y plot in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Using-a-For-Loop-with-X-by-Y-plot/m-p/46832#M26679</link>
    <description>&lt;P&gt;This works.&amp;nbsp; Thank you!&lt;/P&gt;</description>
    <pubDate>Tue, 07 Nov 2017 01:55:50 GMT</pubDate>
    <dc:creator>scottdprm</dc:creator>
    <dc:date>2017-11-07T01:55:50Z</dc:date>
    <item>
      <title>Using a For Loop with X by Y plot</title>
      <link>https://community.jmp.com/t5/Discussions/Using-a-For-Loop-with-X-by-Y-plot/m-p/46830#M26677</link>
      <description>&lt;P&gt;I am trying to recreate the script below using a loop (this script works, but I would like it to run as a loop so that it treats each data set the same way):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;bivariate(
Y( :name( "1st Thickness PST" ) ),
 X( :site ),
By( :Lot ),
Fit Where( :Slot_id == 1, Fit Each Value( {Line Color( {213, 72, 87} )} ) ),
Fit Where( :Slot_id == 2, Fit Each Value( {Line Color( {57, 177, 67} )} ) ),
Fit Where( :Slot_id == 3, Fit Each Value( {Line Color( {64, 111, 223} )} ) ),
Fit Where( :Slot_id == 4, Fit Each Value( {Line Color( {207, 121, 38} )} ) ),
Fit Where( :Slot_id == 5, Fit Each Value( {Line Color( {33, 189, 145} )} ) ),
Fit Where( :Slot_id == 6, Fit Each Value( {Line Color( {161, 44, 220} )} ) ),
Fit Where( :Slot_id == 7, Fit Each Value( {Line Color( {200, 193, 39} )} ) ),
Fit Where( :Slot_id == 8, Fit Each Value( {Line Color( {31, 182, 182} )} ) ),
Fit Where( :Slot_id == 9, Fit Each Value( {Line Color( {201, 37, 205} )} ) ),
Fit Where( :Slot_id == 10, Fit Each Value( {Line Color( {145, 183, 32} )} ) ),
Fit Where( :Slot_id == 11, Fit Each Value( {Line Color( {35, 157, 195} )} ) ),
Fit Where( :Slot_id == 12, Fit Each Value( {Line Color( {210, 38, 158} )} ) ),
Fit Where( :Slot_id == 13, Fit Each Value( {Line Color( {141, 165, 48} )} ) ),
Fit Where( :Slot_id == 14, Fit Each Value( {Line Color( {106, 191, 140} )} ) ),
Fit Where( :Slot_id == 15, Fit Each Value( {Line Color( {23, 67, 132} )} ) ),
Fit Where( :Slot_id == 16, Fit Each Value( {Line Color( {144, 81, 160} )} ) ),
Fit Where( :Slot_id == 17, Fit Each Value( {Line Color( {220, 133, 105} )} ) ),
Fit Where( :Slot_id == 18, Fit Each Value( {Line Color( {97, 136, 48} )} ) ),
Fit Where( :Slot_id == 19, Fit Each Value( {Line Color( {41, 228, 161} )} ) ),
Fit Where( :Slot_id == 20, Fit Each Value( {Line Color( {155, 162, 199} )} ) ),
Fit Where( :Slot_id == 21, Fit Each Value( {Line Color( {109, 28, 105} )} ) ),
Fit Where( :Slot_id == 22, Fit Each Value( {Line Color( {160, 109, 62} )} ) ),
Fit Where( :Slot_id == 23, Fit Each Value( {Line Color( {127, 228, 79} )} ) ),
Fit Where( :Slot_id == 24, Fit Each Value( {Line Color( {53, 113, 105} )} ) ),
Fit Where( :Slot_id == 25, Fit Each Value( {Line Color( {55, 42, 208} )} ) ),
 SendToReport(
Dispatch( {}, "1", ScaleBox, {Label Row( Show Major Grid( 1 ) )} ),
Dispatch( {}, "2", ScaleBox, {Minor Ticks( 1 ), Label Row( Show Major Grid( 1 ) )} ),
Dispatch( {}, "Bivar Plot", FrameBox, {Frame Size( 655, 344 ), Marker Size( 3 )} )
)
);&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;This generates the data that I need but I don't understand why the script below does not. It will generate a plot but without "fit each value" lines and color assignments for each slot_id in the loop&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;R = [213, 57, 64, 207, 33, 161, 200, 31, 201, 145, 35, 210, 141, 106, 23, 144, 220, 97, 41, 155, 109, 160, 127, 53, 55];
G = [72, 177, 111, 121, 189, 44, 193, 182, 37, 183, 157, 38, 165, 191, 67, 81, 133, 136, 228, 162, 28, 109, 228, 113, 42];
B = [87, 67, 223, 38, 145, 220, 39, 182, 205, 32, 195, 158, 48, 140, 132, 160, 105, 48, 161, 199, 105, 62, 79, 105, 208];
SlotNums = Associative Array( :slot_id );
UniqueSlots = slotnums &amp;lt;&amp;lt; get keys;
For( i = 1, i &amp;lt;= N Items( uniqueslots ), i++,
If( i == 1,
lines = Eval(
"Fitwhere(:Slot_id == " || Char( uniqueslots[i] ) || ", " || "Fit Each Value( {Line Color( {" || Char( R[i] ) || ", " || Char( G[i] ) ||
", " || Char( B[i] ) || "} )} )),"
 )
);
If( i &amp;lt; N Items( uniqueslots ),
Lines = Char( lines ) || Eval(
"Fitwhere(:Slot_id == " || Char( uniqueslots[i] ) || ", " || "Fit Each Value( {Line Color( {" || Char( R[i] ) || ", " || Char( G[i] ) ||
", " || Char( B[i] ) || "} )} )),"
 )
);
If( i == N Items( uniqueslots ),
Lines = Char( lines ) || Eval(
"Fitwhere(:Slot_id == " || Char( uniqueslots[i] ) || ", " || "Fit Each Value( {Line Color( {" || Char( R[i] ) || ", " || Char( G[i] ) ||
", " || Char( B[i] ) || "} )} ))"
 )
 );
);
　
bivariate(
Y( :name( "1st Thickness PST" ) ),
 
X( :site ),
By( :Lot ),
Parse( lines ),
 
SendToReport(
Dispatch( {}, "1", ScaleBox, {Label Row( Show Major Grid( 1 ) )} ),
Dispatch( {}, "2", ScaleBox, {Minor Ticks( 1 ), Label Row( Show Major Grid( 1 ) )} ),
Dispatch( {}, "Bivar Plot", FrameBox, {Frame Size( 655, 344 ), Marker Size( 3 )} )
 
)
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;Can anyone suggest a method for getting this to work?&lt;/P&gt;</description>
      <pubDate>Tue, 07 Nov 2017 01:10:38 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Using-a-For-Loop-with-X-by-Y-plot/m-p/46830#M26677</guid>
      <dc:creator>scottdprm</dc:creator>
      <dc:date>2017-11-07T01:10:38Z</dc:date>
    </item>
    <item>
      <title>Re: Using a For Loop with X by Y plot</title>
      <link>https://community.jmp.com/t5/Discussions/Using-a-For-Loop-with-X-by-Y-plot/m-p/46831#M26678</link>
      <description>&lt;P&gt;It appears that the parsing of your code is not connecting the "Lines".&amp;nbsp; The following solution will get what you want&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;R = [213, 57, 64, 207, 33, 161, 200, 31, 201, 145, 35, 210, 141, 106, 23, 144, 220, 97, 41, 155, 109, 160, 127, 53, 55];
G = [72, 177, 111, 121, 189, 44, 193, 182, 37, 183, 157, 38, 165, 191, 67, 81, 133, 136, 228, 162, 28, 109, 228, 113, 42];
B = [87, 67, 223, 38, 145, 220, 39, 182, 205, 32, 195, 158, 48, 140, 132, 160, 105, 48, 161, 199, 105, 62, 79, 105, 208];
SlotNums = Associative Array( :slot_id );
UniqueSlots = slotnums &amp;lt;&amp;lt; get keys;
For( i = 1, i &amp;lt;= N Items( uniqueslots ), i++,
	If( i == 1,
		lines = Eval(
			"Fitwhere(:Slot_id == " || Char( uniqueslots[i] ) || ", " || "Fit Each Value( {Line Color( {" || Char( R[i] ) ||
			", " || Char( G[i] ) || ", " || Char( B[i] ) || "} )} )),"
		)
	);
	If( i &amp;lt; N Items( uniqueslots ),
		Lines = Char( lines ) || Eval(
			"Fitwhere(:Slot_id == " || Char( uniqueslots[i] ) || ", " || "Fit Each Value( {Line Color( {" || Char( R[i] ) ||
			", " || Char( G[i] ) || ", " || Char( B[i] ) || "} )} )),"
		)
	);
	If( i == N Items( uniqueslots ),
		Lines = Char( lines ) || Eval(
			"Fitwhere(:Slot_id == " || Char( uniqueslots[i] ) || ", " || "Fit Each Value( {Line Color( {" || Char( R[i] ) ||
			", " || Char( G[i] ) || ", " || Char( B[i] ) || "} )} ))"
		)
	);
);
　
Eval(
	Parse(
		"bivariate(
	Y( :name( \!"1st Thickness PST\!" ) ), 
 
	X( :site ),
	By( :Lot ),
	" || lines ||
		"), 
 
	SendToReport(
		Dispatch( {}, \!"1\!", ScaleBox, {Label Row( Show Major Grid( 1 ) )} ),
		Dispatch( {}, \!"2\!", ScaleBox, {Minor Ticks( 1 ), Label Row( Show Major Grid( 1 ) )} ),
		Dispatch( {}, \!"Bivar Plot\!", FrameBox, {Frame Size( 655, 344 ), Marker Size( 3 )} )
 
	)
);"
	)
);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 07 Nov 2017 01:31:46 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Using-a-For-Loop-with-X-by-Y-plot/m-p/46831#M26678</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2017-11-07T01:31:46Z</dc:date>
    </item>
    <item>
      <title>Re: Using a For Loop with X by Y plot</title>
      <link>https://community.jmp.com/t5/Discussions/Using-a-For-Loop-with-X-by-Y-plot/m-p/46832#M26679</link>
      <description>&lt;P&gt;This works.&amp;nbsp; Thank you!&lt;/P&gt;</description>
      <pubDate>Tue, 07 Nov 2017 01:55:50 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Using-a-For-Loop-with-X-by-Y-plot/m-p/46832#M26679</guid>
      <dc:creator>scottdprm</dc:creator>
      <dc:date>2017-11-07T01:55:50Z</dc:date>
    </item>
    <item>
      <title>Re: Using a For Loop with X by Y plot</title>
      <link>https://community.jmp.com/t5/Discussions/Using-a-For-Loop-with-X-by-Y-plot/m-p/46833#M26680</link>
      <description>&lt;P&gt;I am late to the party but here is another way that uses Eval( Parse () ) on smaller strings.&amp;nbsp; This &lt;EM&gt;might&lt;/EM&gt; be easier to debug.&amp;nbsp; If you only want to see the visualization another option might be to use graph builder (bottom of this script).&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;names default to here( 1 ) ;

//Sample data, add some categorical colums
dt = open( "$SAMPLE_DATA/football.jmp" );

dt &amp;lt;&amp;lt; New Column( "Height Binned",
	Numeric, "Ordinal", Format( "Best", 12 ),
	Formula( Round( :Height * 2, -1 ) ) );

dt &amp;lt;&amp;lt; New Column( "Weight Binned",
	Numeric, "Ordinal", Format( "Best", 12 ),
	Formula( Round( :Weight, -1 ) ) );

//colors
ColorList = {
	[213, 72, 87], [57, 177, 67], 
	[64, 111, 223], [33, 121, 38]
};

Color = function( {n}, ColorList[ mod(n, n items( ColorList ) ) ] );

//base plot
bv = dt &amp;lt;&amp;lt; Bivariate(
	Y( :Speed ),
	X( :Weight Binned ),
	By( :Position2 ),
	SendToReport(
		Dispatch( {}, "1", ScaleBox, {Label Row( Show Major Grid( 1 ) )} ),
		Dispatch( {}, "2", ScaleBox, {Minor Ticks( 1 ), Label Row( Show Major Grid( 1 ) )} ),
		Dispatch( {}, "Bivar Plot", FrameBox, {Frame Size( 655, 344 ), Marker Size( 3 )} )
	)
);

//get list of bins to fit, remove missing values
bincol = "Height Binned";
bins = (Associative Array( column(dt, bincol) ) &amp;lt;&amp;lt; get keys);

//add each bin to the chart
if( ( N Items( bins ) &amp;gt; 0 ) ,
	for( i = 1, i &amp;lt;= N Items( bins ), i++,
		s = "bv &amp;lt;&amp;lt; Fit Where( " ||
			if( is missing( bins[i] ), 
				"is missing( :Name( \!"" || bincol || "\!" ) )",
				":Name( \!"" || bincol || "\!" ) == " || 
					char( bins[i] )
			) || 
			", Fit Each Value( Color( " || char( i ) || " ) ) )";
		show(s);
		Eval( Parse( s ) );
	)
);

//Graph builder option
dt &amp;lt;&amp;lt; Graph Builder(
	Size( 425, 580 ),
	Show Control Panel( 0 ),
	Variables(
		X( :Weight Binned ),
		Y( :Speed ),
		Group Y( :Position2 ),
		Overlay( :Height Binned )
	),
	Elements( Line( X, Y, Legend( 17 ) ), Points( X, Y, Legend( 18 ) ) )
);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Nov 2017 04:37:47 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Using-a-For-Loop-with-X-by-Y-plot/m-p/46833#M26680</guid>
      <dc:creator>ih</dc:creator>
      <dc:date>2017-11-07T04:37:47Z</dc:date>
    </item>
  </channel>
</rss>

