<?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: [JSL]  add reference lines in graph builder with formula in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/JSL-add-reference-lines-in-graph-builder-with-formula/m-p/722595#M90491</link>
    <description>&lt;P&gt;Hello Jarmo,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;That works great, thanks a lot for your help!!!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Julien&lt;/P&gt;</description>
    <pubDate>Wed, 07 Feb 2024 19:15:40 GMT</pubDate>
    <dc:creator>Voizingu</dc:creator>
    <dc:date>2024-02-07T19:15:40Z</dc:date>
    <item>
      <title>[JSL]  add reference lines in graph builder with formula</title>
      <link>https://community.jmp.com/t5/Discussions/JSL-add-reference-lines-in-graph-builder-with-formula/m-p/722385#M90464</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I am fairly new to JMP and I would like to be able to add variable references lines based on formula in the graph builder.&lt;/P&gt;&lt;P&gt;When I plot the Y with several X (groups), I would like to generate for each X in graph builder:&lt;/P&gt;&lt;P&gt;- 2 lines with the formula (Mean-4*Std ; Mean+4*Std)&lt;/P&gt;&lt;P&gt;- Fill the range with a color&lt;SPAN class=""&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;- Label with the value on each line&lt;SPAN class=""&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried to add these lines in JSL but without success.&lt;SPAN class=""&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;The following code works for a constant (200), and a simple variable (Column Mean (Y)) but I fail at adding more complexity (calculating the right value for each X group, fill the blank between the 2 lines, add label for the line)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I took a JMP data sample to show a quick example of my goal below (.PNG attached).&lt;/P&gt;&lt;P&gt;Thanks a lot for your help&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Open( "$SAMPLE_DATA/Cholesterol Stacked.jmp" );
temp = Graph Builder(
	Size( 715, 637 ),
	Variables( Y( :Y ), Group X( :Treatment ) ),
	Elements( Points( Y, Legend( 5 ) ) ),
	SendToReport(
		Dispatch(
			{},
			"Y",
			ScaleBox,
			{Min( -123.790318945935 ), Max( 574.600650636745 ), Inc( 100 ),
			Minor Ticks( 1 )}
		)
	)
);


DataMean = 100;   /* that code works with a constant*/
DataMean2 = Col Mean( :Y ); /* that code works with a simple variable */ 
report(temp)[axisbox(2)] &amp;lt;&amp;lt; Add Ref Line( DataMean, "solid", red, "label1", 1 );
report(temp)[axisbox(2)] &amp;lt;&amp;lt; Add Ref Line( DataMean2, "solid", red, "label2", 1 );&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Untitled.png" style="width: 999px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/60955i67D553F7CD89B1C5/image-size/large?v=v2&amp;amp;px=999" role="button" title="Untitled.png" alt="Untitled.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 07 Feb 2024 05:50:38 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/JSL-add-reference-lines-in-graph-builder-with-formula/m-p/722385#M90464</guid>
      <dc:creator>Voizingu</dc:creator>
      <dc:date>2024-02-07T05:50:38Z</dc:date>
    </item>
    <item>
      <title>Re: [JSL]  add reference lines in graph builder with formula</title>
      <link>https://community.jmp.com/t5/Discussions/JSL-add-reference-lines-in-graph-builder-with-formula/m-p/722394#M90467</link>
      <description>&lt;P&gt;To calculate mean for each of the groups, you can create new column to your table using Col Mean with ByVar, other option is to use Summarize function (or create summary table).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Generally I would first trying to build something like this by creating new columns and using multiple plot types overlaid. New columns for lines and adding line chart.&amp;nbsp;Getting to this point is easy&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jthi_0-1707290074687.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/60958iFBB27429AFA32C1B/image-size/medium?v=v2&amp;amp;px=400" role="button" title="jthi_0-1707290074687.png" alt="jthi_0-1707290074687.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

dt = Open("$SAMPLE_DATA/Cholesterol Stacked.jmp");

dt &amp;lt;&amp;lt; New Column("NegLimit", Numeric, Continuous, Formula(
	Col Mean(:Y, :Treatment) - 4 * Col Std Dev(:Y, :Treatment)
));

dt &amp;lt;&amp;lt; New Column("PosLimit", Numeric, Continuous, Formula(
	Col Mean(:Y, :Treatment) + 4 * Col Std Dev(:Y, :Treatment)
));


gb = dt &amp;lt;&amp;lt; Graph Builder(
	Size(673, 592),
	Show Control Panel(0),
	Variables(
		Y(:Y),
		Y(:NegLimit, Position(1)),
		Y(:PosLimit, Position(1)),
		Group X(:Treatment)
	),
	Elements(
		Points(Y(1), Legend(5)),
		Line(Y(2), Y(3), Legend(7), Fill("Fill Between"))
	),
	SendToReport(
		Dispatch(
			{},
			"Y",
			ScaleBox,
			{Min(-123.790318945935), Max(574.600650636745), Inc(100), Minor Ticks(1)
			}
		)
	)
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then you start working on labels and it can quickly get very messy (labelling definitely isn't strong part of graph builder).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;These could of course be built using graphic scripts, but how that should be scripted is 100% dependent on your data and your visualization (there is usually quite a lot to take into account).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Edit:&lt;/P&gt;
&lt;P&gt;One option on how far you can get with new columns, new rows and graph builder&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jthi_1-1707291819337.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/60960i2AACFA1522E7A5A8/image-size/medium?v=v2&amp;amp;px=400" role="button" title="jthi_1-1707291819337.png" alt="jthi_1-1707291819337.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;LI-SPOILER&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

dt = Open("$SAMPLE_DATA/Cholesterol Stacked.jmp");

dt &amp;lt;&amp;lt; New Column("NegLimit", Numeric, Continuous, Formula(
	Col Mean(:Y, :Treatment) - 4 * Col Std Dev(:Y, :Treatment)
));

dt &amp;lt;&amp;lt; New Column("PosLimit", Numeric, Continuous, Formula(
	Col Mean(:Y, :Treatment) + 4 * Col Std Dev(:Y, :Treatment)
));

dt &amp;lt;&amp;lt; New Column("MarkerVal", Numeric, Continuous, Formula(
	If(!IsMissing(Days),
		.
	, Row() == Col Min(Row(), :Treatment, :Days),
		:NegLimit - 10
	,
		:PosLimit + 10
		
	)
));

dt &amp;lt;&amp;lt; New Column("MarkerLabel", Character, Continuous, Label(1), Formula(
	If(!IsMissing(Days),
		.
	, Row() == Col Min(Row(), :Treatment, :Days),
		"-4Sigma " || Char(Round(:NegLimit, 2))
	,
		"+4Sigma " || Char(Round(:PosLimit, 2))
	)
));

Summarize(dt, uniq_treatments = by(:Treatment));
rows_added = 0;
For Each({cur_treatment}, uniq_treatments,
	dt &amp;lt;&amp;lt; Add Rows({Treatment = cur_treatment});
	dt &amp;lt;&amp;lt; Add Rows({Treatment = cur_treatment});
	rows_added = rows_added + 2;
);
dt &amp;lt;&amp;lt; Select Rows((N Rows(dt) - rows_added + 1)::N Rows(dt)) &amp;lt;&amp;lt; Label(1) &amp;lt;&amp;lt; Clear Select;

gb = dt &amp;lt;&amp;lt; Graph Builder(
	Size(1126, 772),
	Show Control Panel(0),
	Variables(
		Y(:Y, Combine("Merged")),
		Y(:NegLimit, Position(1), Combine("Merged")),
		Y(:PosLimit, Position(1), Combine("Merged")),
		Y(:MarkerVal, Position(1), Combine("Merged")),
		Group X(:Treatment)
	),
	Elements(
		Line(
			Y(2),
			Y(3),
			Legend(7),
			Fill("Fill Between"),
			Missing Factors("Treat as Missing"),
			Missing Values("Connect Faded")
		),
		Points(Y(1), Legend(5)),
		Points(Y(4), Legend(11))
	),
	SendToReport(
		Dispatch(
			{},
			"400",
			ScaleBox,
			{Legend Model(
				7,
				Properties(0, {Line Color(16)}, Item ID("Mean(NegLimit)", 1)),
				Properties(1, {Line Color(16)}, Item ID("Mean(PosLimit)", 1)),
				Properties(
					2,
					{Fill Color(37)},
					Item ID("Mean(NegLimit)..Mean(PosLimit)", 1)
				)
			), Legend Model(
				11,
				Properties(
					0,
					{Line Color(0), Marker(" "), Marker Size(0)},
					Item ID("MarkerVal", 1)
				)
			)}
		),
		Dispatch(
			{},
			"400",
			LegendBox,
			{Legend Position({7, [1, 2, 3], 5, [0], 11, [4]})}
		)
	)
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;/LI-SPOILER&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 07 Feb 2024 07:44:40 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/JSL-add-reference-lines-in-graph-builder-with-formula/m-p/722394#M90467</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2024-02-07T07:44:40Z</dc:date>
    </item>
    <item>
      <title>Re: [JSL]  add reference lines in graph builder with formula</title>
      <link>https://community.jmp.com/t5/Discussions/JSL-add-reference-lines-in-graph-builder-with-formula/m-p/722595#M90491</link>
      <description>&lt;P&gt;Hello Jarmo,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;That works great, thanks a lot for your help!!!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Julien&lt;/P&gt;</description>
      <pubDate>Wed, 07 Feb 2024 19:15:40 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/JSL-add-reference-lines-in-graph-builder-with-formula/m-p/722595#M90491</guid>
      <dc:creator>Voizingu</dc:creator>
      <dc:date>2024-02-07T19:15:40Z</dc:date>
    </item>
  </channel>
</rss>

