cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Browse apps to extend the software in the new JMP Marketplace
Choose Language Hide Translation Bar
Neo
Neo
Level VI

How to set a Reference Line on each page with Page option in Graph Builder?

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)))
);
When it's too good to be true, it's neither
1 ACCEPTED SOLUTION

Accepted Solutions
jthi
Super User

Re: How to set a Reference Line on each page with Page option in Graph Builder?

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();
-Jarmo

View solution in original post

10 REPLIES 10

Re: How to set a Reference Line on each page with Page option in Graph Builder?

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" );
Neo
Neo
Level VI

Re: How to set a Reference Line on each page with Page option in Graph Builder?

@Mark_Bailey  Stops working for me (JMP 16.2) if I invoke Local Data Filter on Age after plotting, as below

Neo_0-1726153593695.png

 

When it's too good to be true, it's neither
jthi
Super User

Re: How to set a Reference Line on each page with Page option in Graph Builder?

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

-Jarmo
Neo
Neo
Level VI

Re: How to set a Reference Line on each page with Page option in Graph Builder?

@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?

When it's too good to be true, it's neither
jthi
Super User

Re: How to set a Reference Line on each page with Page option in Graph Builder?

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();

jthi_0-1726163173773.png

 

-Jarmo
hogi
Level XII

Re: How to set a Reference Line on each page with Page option in Graph Builder?

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 )}
		)
	)
);

 

hogi_0-1726169228867.png

 

 

jthi
Super User

Re: How to set a Reference Line on each page with Page option in Graph Builder?

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.

-Jarmo
Neo
Neo
Level VI

Re: How to set a Reference Line on each page with Page option in Graph Builder?

@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.

When it's too good to be true, it's neither
jthi
Super User

Re: How to set a Reference Line on each page with Page option in Graph Builder?

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.

-Jarmo