The following script plots some charts with the page option in graph builder? How to I set a horizontal reference line, for each chart, say at Weight = 80Kg and label it (80kg) using JSL?
(I need the reference line to remain even if there is a change in the number of charts plotted)
Names Default To Here(1);
dt = open("$SAMPLE_DATA/Big Class.jmp");
gb = dt << Graph Builder(
Size(528, 2954),
Show Control Panel(0),
Variables(X(:height), Y(:weight), Page(:age)),
Elements(Points(X, Y, Legend(15)), Smoother(X, Y, Legend(16)))
);
And graphic script might be an option
Names Default To Here(1);
dt = Open("$SAMPLE_DATA/Big Class.jmp");
gb = dt << Graph Builder(
Size(528, 984),
Show Control Panel(0),
Variables(X(:height), Y(:weight), Page(:age)),
Elements(
Points(X, Y(1), Legend(15)),
Smoother(X, Y(1), Legend(16))
)
);
(Report(gb) << XPath("//FrameBox")) << Add Graphics Script(
Pen Color("Red");
Text Color("red");
Text(Right Justified, {X Origin() + X Range(), 80}, "Reference");
H Line(80);
);
gb << Local Data Filter(
Add Filter(
columns(:age),
Display(:age, N Items(6))
)
);
Write();
Names Default To Here(1);
dt = open("$SAMPLE_DATA/Big Class.jmp");
gb = dt << Graph Builder(
Size(528, 2954),
Show Control Panel(0),
Variables(X(:height), Y(:weight), Page(:age)),
Elements(Points(X, Y, Legend(15)), Smoother(X, Y, Legend(16)))
);
axis = gb << XPath( "//AxisBox" );
Summarize( page = By( :age ) );
axis[2::(2*NItems( page ))::2] << Add Ref Line( 80, "Solid", "Red", "Reference" );
@Mark_Bailey Stops working for me (JMP 16.2) if I invoke Local Data Filter on Age after plotting, as below
Easiest way is to add new column to your data table with same value for each of the rows and add that to your graph. This will work with filters
@jthi your suggestion works fine, except that I would like the line label to be on the right. Is there a way to change the location of the line label?
I don't remember which options are available in JMP16 as I'm mostly using JMP18 nowadays (with some JMP17 mixed in)
Names Default To Here(1);
dt = Open("$SAMPLE_DATA/Big Class.jmp");
dt << New Column("Ref", Numeric, Continuous, Set Each Value(80));
gb = dt << Graph Builder(
Size(528, 984),
Show Control Panel(0),
Variables(X(:height), Y(:weight), Y(:Ref, Position(1)), Page(:age)),
Elements(
Points(X, Y(1), Legend(15)),
Smoother(X, Y(1), Legend(16)),
Line(Y(2), Legend(17))
),
Local Data Filter(
Add Filter(
columns(:age),
Where(:age == {12, 15}),
Display(:age, N Items(6))
)
),
SendToReport(
Dispatch({}, "400", ScaleBox,
{Legend Model(
17,
Level Name(0, "Ref", Item ID("Mean(Ref)", 1)),
Properties(
0,
{Line Label Properties(
{Name Label(1), Name Label Position("Last")}
)},
Item ID("Mean(Ref)", 1)
)
)}
)
)
);
Write();
No need to change the data table.
Replicating the axis setting via
Link Page Axes( "Y Only" )copies the reference lines as well.
e.g.
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
Graph Builder(
Link Page Axes( "Y Only" ),
Variables( X( :height ), Y( :weight ), Page( :sex ), Overlay( :sex ) ),
Elements( Points( X, Y), Smoother( X, Y) ),
SendToReport(
Dispatch( {}, "weight", ScaleBox,
{Add Ref Line( 100, "Solid", "Black", "", 1 )}
)
)
);
That is also an option, but you do lose one of the benefits of Page: having different axis scaling for different "pages". It might not be an issue here and might be even a benefit.
@jthi Thanks.
Name Label Position("Last")does not seem to be available/ working in JMP 16.2.
@hogi Reason for me choosing the Page option is so that I can get different y-axis scaling. I am sure there are other ways of doing this, but Page option seems easiest.
Then you might have to go back to Mark's solution and use filter change handler with it. Again no idea what are the limitations of JMP16 with this option
Names Default To Here(1);
dt = Open("$SAMPLE_DATA/Big Class.jmp");
gb = dt << Graph Builder(
Size(528, 984),
Show Control Panel(0),
Variables(X(:height), Y(:weight), Page(:age)),
Elements(
Points(X, Y(1), Legend(15)),
Smoother(X, Y(1), Legend(16))
),
Local Data Filter(
Add Filter(
columns(:age),
Where(:age == {12, 15}),
Display(:age, N Items(6))
)
)
);
add_reflines = EvalExpr(
axis = Expr(gb) << XPath("//AxisBox");
axis[2::N Items(axis)::2] << Add Ref Line(80, "Solid", "Red", "Reference", 1, 1, Label Settings({Opposite Axis(1)}));
);
f = Function({a}, add_reflines);
ldf = (Report(gb) << top parent)[OutlineBox("Local Data Filter")] << Get Scriptable Object;
rs = ldf << Make Filter Change Handler(f);
add_reflines;
Write();
This isn't the most robust option to do this, but it is fairly simple one.