<?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: Best way to plot GraphBuilder plot with multiple Y variables using JSL in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Best-way-to-plot-GraphBuilder-plot-with-multiple-Y-variables/m-p/549991#M76629</link>
    <description>&lt;P&gt;Nice!&amp;nbsp; Thanks for adding that touch.&amp;nbsp; Wish I'd have tried that myself!&lt;/P&gt;</description>
    <pubDate>Wed, 28 Sep 2022 00:45:02 GMT</pubDate>
    <dc:creator>pmroz</dc:creator>
    <dc:date>2022-09-28T00:45:02Z</dc:date>
    <item>
      <title>Best way to plot GraphBuilder plot with multiple Y variables using JSL</title>
      <link>https://community.jmp.com/t5/Discussions/Best-way-to-plot-GraphBuilder-plot-with-multiple-Y-variables/m-p/549497#M76594</link>
      <description>&lt;P&gt;All,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'd like to ask for an input on the best way to script a GB plot with multiple parameters.&lt;/P&gt;&lt;P&gt;Let's say I have a table like this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;New Table( "Untitled 140",
	Add Rows( 12 ),
	New Column( "Category",
		Character,
		"Nominal",
		Set Values( {"A", "A", "A", "B", "B", "B", "C", "C", "C", "D", "D", "D"} )
	),
	New Column( "Value1",
		Numeric,
		"Continuous",
		Format( "Best", 12 ),
		Set Values( [1, 4, 2, 3, 6, 2, 3, 5, 4, 1, 3, 6] )
	),
	New Column( "Value2",
		Numeric,
		"Continuous",
		Format( "Best", 12 ),
		Set Values( [6, 3, 5, 2, 8, 6, 5, 2, 6, 3, 5, 4] )
	)
)&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;And I want to script a plot like this:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="2022-09-26 11_31_14-Window.png" style="width: 639px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/45798i2EAC43146CDA9714/image-size/large?v=v2&amp;amp;px=999" role="button" title="2022-09-26 11_31_14-Window.png" alt="2022-09-26 11_31_14-Window.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;where the autogenerated script looks like this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Graph Builder(
	Size( 522, 450 ),
	Show Control Panel( 0 ),
	Variables( X( :Category ), Y( :Value1 ), Y( :Value2, Position( 1 ) ) ),
	Elements( Bar( X, Y( 1 ), Y( 2 ), Legend( 4 ), Summary Statistic( "Range" ) ) )
)&lt;/CODE&gt;;&lt;/PRE&gt;&lt;P&gt;with the catch that there is an arbitrary number of Y columns and the names are also arbitrary.&lt;/P&gt;&lt;P&gt;For plots like Variability plot I would something like this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;parameters = {:"Value1"n, :"Value2"n};
yExpr = Expr( Y() );
For Each( {value, index}, parameters, Insert Into( yExpr, Name Expr( value ), 1 ) );

Eval(
	Substitute(
			Expr(
				Variability Chart( placeholder, X( :Category ),  Std Dev Chart( 0 )  )
			),
		Expr( placeholder ), Name Expr( yExpr )
	)
);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;where I receive the names of the columns as a list and then construct a Y expression and then put it into the script for the chart. It would give me a list of variability plots, but that's OK with me.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If I want to take the same route in case of the GB it looks like I will have to construct two expressions:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Y( :Value1 ), Y( :Value2, Position( 1 ) )&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;and&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Elements( Bar( X, Y( 1 ), Y( 2 ), Legend( 4 ), Summary Statistic( "Range" ) ) )&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Which is essentially the whole script.&lt;/P&gt;&lt;P&gt;My question: Is there a better way rather than making bunch of substitutions with expressions to assemble those two lines?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Jun 2023 15:59:05 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Best-way-to-plot-GraphBuilder-plot-with-multiple-Y-variables/m-p/549497#M76594</guid>
      <dc:creator>miguello</dc:creator>
      <dc:date>2023-06-09T15:59:05Z</dc:date>
    </item>
    <item>
      <title>Re: Best way to plot GraphBuilder plot with multiple Y variables using JSL</title>
      <link>https://community.jmp.com/t5/Discussions/Best-way-to-plot-GraphBuilder-plot-with-multiple-Y-variables/m-p/549542#M76599</link>
      <description>&lt;P&gt;Ok, this is how I solved it, but is there a simpler way? Can't believe that to script such a simple thing I need to go into that kind of complexity...:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;parameters = {:"Value1"n, :"Value2"n};

yExpr = Expr( Y() );
yExprPos = Expr( Y( Position( 1 ) ) );
barExpr = Expr(
	Bar( X, Summary Statistic( "Range" ) )
);
yNExpr = Expr( Y() );
variablesExpr = Expr(
	Variables( X( :Category ) )
);

For Each( {value, index}, parameters,
	Insert Into( yExpr, Name Expr( value ), 1 );
	yExprPos = Expr( Y( Position( 1 ) ) );
	Insert Into( yExprPos, Name Expr( value ), 1 );
	Insert Into( variablesExpr, Name Expr( yExprPos ) );
	//This is for Y(1) etc. in Bar()
	yNExpr = Expr( Y() );
	Insert Into( yNExpr, Name Expr( index ) );
	
	Insert Into( barExpr, Name Expr( yNExpr ), 2 );
);


//Name Expr( yExpr );
Show(Name Expr( variablesExpr ));
Show(Name Expr( barExpr ));

gbExpr = Expr(
	Graph Builder( Size( 522, 450 ), Show Control Panel( 0 ), placeholder1, Elements( placeholder2 ) )
	
);

Eval( 
	Substitute( 
		Substitute( 
			Name Expr(gbExpr),    
			Expr( placeholder1 ), 
			Name Expr( variablesExpr )
		), 
		Expr( placeholder2 ), 
		Name Expr( barExpr ) 
	) 
);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 26 Sep 2022 20:10:32 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Best-way-to-plot-GraphBuilder-plot-with-multiple-Y-variables/m-p/549542#M76599</guid>
      <dc:creator>miguello</dc:creator>
      <dc:date>2022-09-26T20:10:32Z</dc:date>
    </item>
    <item>
      <title>Re: Best way to plot GraphBuilder plot with multiple Y variables using JSL</title>
      <link>https://community.jmp.com/t5/Discussions/Best-way-to-plot-GraphBuilder-plot-with-multiple-Y-variables/m-p/549549#M76600</link>
      <description>&lt;P&gt;I have usually used similar methods as you to build such graph builders, this might be a good read&lt;LI-MESSAGE title="Re: Can you construct this without writing expression a string?" uid="369448" url="https://community.jmp.com/t5/Discussions/Can-you-construct-this-without-writing-expression-as-a-string/m-p/369448#U369448" discussion_style_icon_css="lia-mention-container-editor-message lia-img-icon-forum-thread lia-fa-icon lia-fa-forum lia-fa-thread lia-fa"&gt;&lt;/LI-MESSAGE&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 26 Sep 2022 19:46:22 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Best-way-to-plot-GraphBuilder-plot-with-multiple-Y-variables/m-p/549549#M76600</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2022-09-26T19:46:22Z</dc:date>
    </item>
    <item>
      <title>Re: Best way to plot GraphBuilder plot with multiple Y variables using JSL</title>
      <link>https://community.jmp.com/t5/Discussions/Best-way-to-plot-GraphBuilder-plot-with-multiple-Y-variables/m-p/549625#M76605</link>
      <description>&lt;P&gt;This still uses loops to build those expressions, but it concatenates lists of arguments instead of substituting them:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names default to here(1);

//call another function (f) with the arguments provided in a list (l)
do.call = function({l,f}, 
	Substitute(
		Name Expr(l),
		Expr({}),
		Name Expr(f)
	);
);

dt = New Table( "Data",
	Add Rows( 12 ),
	New Column( "Category", Character, "Nominal",
		Set Values( {"A", "A", "A", "B", "B", "B", "C", "C", "C", "D", "D", "D"} )
	),
	New Column( "Value1", Numeric, "Continuous", Format( "Best", 12 ),
		Set Values( [1, 4, 2, 3, 6, 2, 3, 5, 4, 1, 3, 6] )
	),
	New Column( "Value2", Numeric, "Continuous", Format( "Best", 12 ),
		Set Values( [6, 3, 5, 2, 8, 6, 5, 2, 6, 3, 5, 4] )
	)
);

vars = {:Value1, :Value2};

VarExpr = do.call(
	{ X( :Category ) } || transform each({v}, vars, eval expr( Y( Expr( Name Expr( v ) ), Position( 1 ) ) ) ),
	expr(Variables())
);

BarExpr = do.call(
	{ X } || transform each({v, i}, vars, eval expr( Y( Expr( i ) ) ) ) || { Legend( 4 ), Summary Statistic( "Range" ) },
	expr(Bar())
);

Eval( Eval Expr(
	dt &amp;lt;&amp;lt; Graph Builder(
		Size( 522, 450 ),
		Show Control Panel( 0 ),
		Expr( Name Expr( VarExpr ) ),
		Elements( Expr( Name Expr( BarExpr ) ) )
	)
) );&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 26 Sep 2022 21:58:13 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Best-way-to-plot-GraphBuilder-plot-with-multiple-Y-variables/m-p/549625#M76605</guid>
      <dc:creator>ih</dc:creator>
      <dc:date>2022-09-26T21:58:13Z</dc:date>
    </item>
    <item>
      <title>Re: Best way to plot GraphBuilder plot with multiple Y variables using JSL</title>
      <link>https://community.jmp.com/t5/Discussions/Best-way-to-plot-GraphBuilder-plot-with-multiple-Y-variables/m-p/549856#M76621</link>
      <description>&lt;P&gt;Don't forget the &lt;STRONG&gt;STACK&lt;/STRONG&gt; command.&amp;nbsp; Requires eval(parse()) but it's pretty clean otherwise.&amp;nbsp; Here's an example with three columns to be plotted.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dt = New Table( "Test",
	Add Rows( 12 ),
	New Column( "Category",
		Character,
		"Nominal",
		Set Values( {"A", "A", "A", "B", "B", "B", "C", "C", "C", "D", "D", "D"} )
	),
	New Column( "Value1",
		Numeric,
		"Continuous",
		Format( "Best", 12 ),
		Set Values( [1, 4, 2, 3, 6, 2, 3, 5, 4, 1, 3, 6] )
	),
	New Column( "Value2",
		Numeric,
		"Continuous",
		Format( "Best", 12 ),
		Set Values( [6, 3, 5, 2, 8, 6, 5, 2, 6, 3, 5, 4] )
	),

	New Column( "Value3",
		Numeric,
		"Continuous",
		Format( "Best", 12 ),
		Set Values( [1, 4, 3, 6, 5, 7, 3, 4, 2, 8, 6, 1] )
	)
);

dt_cols = dt &amp;lt;&amp;lt; get column names(string);
removefrom(dt_cols, 1);	// Remove Category

// Create the list of columns, like this: ":Value1, :Value2, :Value3"
col_list = ":" || concat items(dt_cols, ", :");

stack_str = evalinsert(
"\[dts = dt &amp;lt;&amp;lt; Stack(invisible,
	columns( ^col_list^ ),
	Source Label Column( "Label" ),
	Stacked Data Column( "Data" ))]\");
eval(parse(stack_str));

dts &amp;lt;&amp;lt; Graph Builder(
	Size( 518, 448 ),
	Show Control Panel( 0 ),
	Variables( X( :Category ), Y( :Data ), Overlay( :Label ) ),
	Elements( Bar( X, Y, Legend( 7 ) ) )
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="pmroz_0-1664296624999.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/45851i48EFA29C216EB7EF/image-size/medium?v=v2&amp;amp;px=400" role="button" title="pmroz_0-1664296624999.png" alt="pmroz_0-1664296624999.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 27 Sep 2022 16:37:12 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Best-way-to-plot-GraphBuilder-plot-with-multiple-Y-variables/m-p/549856#M76621</guid>
      <dc:creator>pmroz</dc:creator>
      <dc:date>2022-09-27T16:37:12Z</dc:date>
    </item>
    <item>
      <title>Re: Best way to plot GraphBuilder plot with multiple Y variables using JSL</title>
      <link>https://community.jmp.com/t5/Discussions/Best-way-to-plot-GraphBuilder-plot-with-multiple-Y-variables/m-p/549943#M76627</link>
      <description>&lt;P&gt;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/4550"&gt;@pmroz&lt;/a&gt;&amp;nbsp;here is the same code without Eval(Parse()).&amp;nbsp; I agree this is much cleaner!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names default to here(1);

dt = New Table( "Test",
	Add Rows( 12 ),
	New Column( "Category", Character, "Nominal",
		Set Values( {"A", "A", "A", "B", "B", "B", "C", "C", "C", "D", "D", "D"} ) ),
	New Column( "Value1", Numeric, "Continuous", Format( "Best", 12 ),
		Set Values( [1, 4, 2, 3, 6, 2, 3, 5, 4, 1, 3, 6] ) ),
	New Column( "Value2", Numeric, "Continuous", Format( "Best", 12 ),
		Set Values( [6, 3, 5, 2, 8, 6, 5, 2, 6, 3, 5, 4] ) ),
	New Column( "Value3", Numeric, "Continuous", Format( "Best", 12 ),
		Set Values( [1, 4, 3, 6, 5, 7, 3, 4, 2, 8, 6, 1] ) )
);

dt_cols = dt &amp;lt;&amp;lt; get column references();
remove from(dt_cols, 1);	// Remove Category

dts = dt &amp;lt;&amp;lt; Stack(invisible,
	columns( dt_cols ),
	Source Label Column( "Label" ),
	Stacked Data Column( "Data" )
);
	
dts &amp;lt;&amp;lt; Graph Builder(
	Size( 518, 448 ),
	Show Control Panel( 0 ),
	Variables( X( :Category ), Y( :Data ), Overlay( :Label ) ),
	Elements( Bar( X, Y, Legend( 7 ) ) )
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 27 Sep 2022 21:56:56 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Best-way-to-plot-GraphBuilder-plot-with-multiple-Y-variables/m-p/549943#M76627</guid>
      <dc:creator>ih</dc:creator>
      <dc:date>2022-09-27T21:56:56Z</dc:date>
    </item>
    <item>
      <title>Re: Best way to plot GraphBuilder plot with multiple Y variables using JSL</title>
      <link>https://community.jmp.com/t5/Discussions/Best-way-to-plot-GraphBuilder-plot-with-multiple-Y-variables/m-p/549991#M76629</link>
      <description>&lt;P&gt;Nice!&amp;nbsp; Thanks for adding that touch.&amp;nbsp; Wish I'd have tried that myself!&lt;/P&gt;</description>
      <pubDate>Wed, 28 Sep 2022 00:45:02 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Best-way-to-plot-GraphBuilder-plot-with-multiple-Y-variables/m-p/549991#M76629</guid>
      <dc:creator>pmroz</dc:creator>
      <dc:date>2022-09-28T00:45:02Z</dc:date>
    </item>
  </channel>
</rss>

