<?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: Graph Builder Mean Line in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Graph-Builder-Mean-Line/m-p/193684#M41415</link>
    <description>&lt;P&gt;Here is one way to do it&amp;nbsp; - I use a graphics script for drawing, but the logic for computing the mean and responding to row-state changes is done outside of the drawing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Working: with data table exclude changes and adding or removing of data filters.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Needs work: (1) Data table and Y column are hard-coded.&amp;nbsp; (2) It only works on the most recent report launched from the script.&amp;nbsp; You can't run it multiple times, or use Redo Analysis to create a second working copy of the report.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;NamesDefaultToHere(1);

dt=Open("$SAMPLE_DATA/Big Class.jmp");
gb=dt&amp;lt;&amp;lt;Graph Builder(
	Size( 534, 454 ),
	Show Control Panel( 0 ),
	Variables( X( :height ), Y( :weight ) ),
	Elements( Points( X, Y, Legend( 2 ) ) )
);
rpt=(gb&amp;lt;&amp;lt;Report);

// add or update a mean line that honors exclude flags
updateMeanLine=Function({},
	rpt[FrameBox(1)] &amp;lt;&amp;lt; Remove Graphics Script(1);

	rs = rpt[FrameBox(1)] &amp;lt;&amp;lt; Get Row States;
	val = dt:weight &amp;lt;&amp;lt; Get Values;
	inc = Loc(1-(rs&amp;amp;2));
	m = mean(val[inc]);

	Eval(EvalExpr( rpt[FrameBox(1)] &amp;lt;&amp;lt; Add Graphics Script(
		Pen Color("red");
		Y Function(Expr(m), x);
		Text Color("red");
		Text({X Origin(), Expr(m)}, "Mean=" || Char(Expr(m)));
	)));
);

// listen for row-state changes to dt or data filter
rsupdate = Function( {a},
	If( Is Matrix( a ),
		// row states have changed
		updateMeanLine(),
		// else (a==-1) indicates that filter may have been added or removed
		rsh = rpt[FrameBox(1)] &amp;lt;&amp;lt; Make Row State Handler( dt, rsupdate );
	)
);
rsh = rpt[FrameBox(1)] &amp;lt;&amp;lt; Make Row State Handler( dt, rsupdate );

updateMeanLine();

&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 18 Apr 2019 20:01:44 GMT</pubDate>
    <dc:creator>danschikore</dc:creator>
    <dc:date>2019-04-18T20:01:44Z</dc:date>
    <item>
      <title>Graph Builder Mean Line</title>
      <link>https://community.jmp.com/t5/Discussions/Graph-Builder-Mean-Line/m-p/193431#M41397</link>
      <description>&lt;P&gt;I have a "points" plot in graph builder. I would like to add a mean line to the plot automatically, like one can do in Fit Y by X by selecting Fit Mean. I want it to happen automatically because I have a local data filter that I want to use to filter my data and each time I do so, I want the mean line to update with the mean of the filtered data. Basically, I would like the Mean Line to behave the same way the Line Of Fit currently does in graph builder in this situation. (You might say I would like to add a 0th order line of fit.)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am very new to jmp, so please have patience with my ignorance. I have been trying to adding a script (Customize&amp;gt;Add script). If I could find a way to call the mean I could add&amp;nbsp;Y Function(mean(), x), but I can't figure out the right way to do it. I guess the mean must be accessible because I can add a caption box that shows the mean (and this mean updates depending on how the data is filtered), but I can't figure out how to access this value. Thanks for any help you might have!&lt;/P&gt;</description>
      <pubDate>Thu, 18 Apr 2019 14:07:07 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Graph-Builder-Mean-Line/m-p/193431#M41397</guid>
      <dc:creator>JShef</dc:creator>
      <dc:date>2019-04-18T14:07:07Z</dc:date>
    </item>
    <item>
      <title>Re: Graph Builder Mean Line</title>
      <link>https://community.jmp.com/t5/Discussions/Graph-Builder-Mean-Line/m-p/193684#M41415</link>
      <description>&lt;P&gt;Here is one way to do it&amp;nbsp; - I use a graphics script for drawing, but the logic for computing the mean and responding to row-state changes is done outside of the drawing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Working: with data table exclude changes and adding or removing of data filters.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Needs work: (1) Data table and Y column are hard-coded.&amp;nbsp; (2) It only works on the most recent report launched from the script.&amp;nbsp; You can't run it multiple times, or use Redo Analysis to create a second working copy of the report.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;NamesDefaultToHere(1);

dt=Open("$SAMPLE_DATA/Big Class.jmp");
gb=dt&amp;lt;&amp;lt;Graph Builder(
	Size( 534, 454 ),
	Show Control Panel( 0 ),
	Variables( X( :height ), Y( :weight ) ),
	Elements( Points( X, Y, Legend( 2 ) ) )
);
rpt=(gb&amp;lt;&amp;lt;Report);

// add or update a mean line that honors exclude flags
updateMeanLine=Function({},
	rpt[FrameBox(1)] &amp;lt;&amp;lt; Remove Graphics Script(1);

	rs = rpt[FrameBox(1)] &amp;lt;&amp;lt; Get Row States;
	val = dt:weight &amp;lt;&amp;lt; Get Values;
	inc = Loc(1-(rs&amp;amp;2));
	m = mean(val[inc]);

	Eval(EvalExpr( rpt[FrameBox(1)] &amp;lt;&amp;lt; Add Graphics Script(
		Pen Color("red");
		Y Function(Expr(m), x);
		Text Color("red");
		Text({X Origin(), Expr(m)}, "Mean=" || Char(Expr(m)));
	)));
);

// listen for row-state changes to dt or data filter
rsupdate = Function( {a},
	If( Is Matrix( a ),
		// row states have changed
		updateMeanLine(),
		// else (a==-1) indicates that filter may have been added or removed
		rsh = rpt[FrameBox(1)] &amp;lt;&amp;lt; Make Row State Handler( dt, rsupdate );
	)
);
rsh = rpt[FrameBox(1)] &amp;lt;&amp;lt; Make Row State Handler( dt, rsupdate );

updateMeanLine();

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 18 Apr 2019 20:01:44 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Graph-Builder-Mean-Line/m-p/193684#M41415</guid>
      <dc:creator>danschikore</dc:creator>
      <dc:date>2019-04-18T20:01:44Z</dc:date>
    </item>
  </channel>
</rss>

