cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Try the Materials Informatics Toolkit, which is designed to easily handle SMILES data. This and other helpful add-ins are available in the JMP® Marketplace
Choose Language Hide Translation Bar
LT
LT
Level I

How to set different scale when I use "by"?

Hi,

 

I use "by" function to draw plots one-time.

How could I use script to set different scale?

I tried to use "if" but it didn't work.

Here is my script:

d_graph=dt3 << Graph Builder(
	Size( 1200, 300 ),
	Show Control Panel( 0 ),
	Variables(
		X( :Lot ),
		X( :ReadPoint, Position( 1 ) ),
		Y( :drift% ),
		Group X( :Rel_Test ),
		Color( :Lot )
	),
	Elements( Box Plot( X( 1 ), X( 2 ), Y, Legend( 1 ) ) ),
	By( :Label ),
	SendToReport(
			If(:Label == "IGSS" | :Label == "IGSSR" | :Label == "IDSS",
		(Dispatch(
			{},
			"drift%",
			ScaleBox,
			{Min( 0 ), Max( 20 ), Inc( 5 ), Minor Ticks( 1 ),
			Add Ref Line( 10, "Solid", "Medium Dark Red", "1000%", 1 ),
			Add Ref Line( 5, "Dotted", "Medium Dark Red", "500%", 1 )})),
		(Dispatch(
			{},
			"drift%",
			ScaleBox,
			{Min( -0.25 ), Max( 0.25 ), Inc( 0.05 ), Minor Ticks( 1 ),
			Add Ref Line( 1.2, "Solid", "Medium Dark Red", "20%", 1 ),
			Add Ref Line( 0.8, "Solid", "Medium Dark Red", "-20%", 1 )})))
	  )
   );
1 ACCEPTED SOLUTION

Accepted Solutions
jthi
Super User

Re: How to set different scale when I use "by"?

Here is one scripting solution when using By. Depending where you get the min/max and ref line values, I would most likely move those outside of the For Each loop.

Names Default To Here(1); 

dt = Open("$SAMPLE_DATA/Big Class.jmp");

gbs = dt << Graph Builder(
	SendToByGroup({:age == 12}),
	Size(525, 454),
	Show Control Panel(0),
	Variables(X(:weight), Y(:height)),
	Elements(Points(X, Y, Legend(1)), Smoother(X, Y, Legend(2))),
	By(:age)
);

For Each({gb}, gbs,
	rep = Report(gb);
	yaxis = rep[AxisBox(2)];
	gbtitle = rep[Outline Box(1)] << Get title;
	category = Word(-1, gbtitle, "=");
	If(Contains({"12", "14", "15", "16"}, category),
		minval = 50;
		maxval = 70;
		ref1 = 55;
		ref2 = 65;
		ref1title = "500%";
		ref2title = "1000%";
	, 	Contains({"13"}, category),
		minval = 0;
		maxval = 100;
		ref1 = 5;
		ref2 = 95;
		ref1title = "-20%";
		ref2title = "20%";
	);
	yaxis << Min(minval) << Max(maxval);
	yaxis << Add Ref Line(ref1, "Solid", "Medium Dark Red", ref1title, 1);
	yaxis << Add Ref Line(ref2, "Solid", "Medium Dark Red", ref2title, 1);	
);
-Jarmo

View solution in original post

4 REPLIES 4
jthi
Super User

Re: How to set different scale when I use "by"?

With Graph Builder you might want to use Page instead of By. You have to set all axis separately or use scripting solutions which can get a bit complicated.

 

With Page

Graph Builder(
	Size(525, 2954),
	Show Control Panel(0),
	Variables(X(:weight), Y(:height), Page(:age)),
	Elements(Points(X, Y, Legend(12)), Smoother(X, Y, Legend(13))),
	SendToReport(
		Dispatch({}, "height", ScaleBox(2), {Min(49.55686), Max(71.1300045339471), Inc(5), Minor Ticks(1)}),
		Dispatch({}, "height", ScaleBox(3), {Min(39.2571438997966), Max(67.3579268825169), Inc(5), Minor Ticks(1)}),
		Dispatch({}, "height", ScaleBox(4), {Min(59.60392), Max(70.2079010526316), Inc(2), Minor Ticks(1)}),
		Dispatch({}, "height", ScaleBox(5), {Min(60.2030935251799), Max(67.27), Inc(1), Minor Ticks(0)}),
		Dispatch({}, "height", ScaleBox(6), {Min(58.60392), Max(69.3254618181818), Inc(2), Minor Ticks(1)}),
		Dispatch({}, "height", ScaleBox(7), {Min(60.1377273502176), Max(70.192348647039), Inc(2), Minor Ticks(1)})
	)
);

With By

Graph Builder(
	SendToByGroup({:age == 12}),
	Size(525, 454),
	Show Control Panel(0),
	Variables(X(:weight), Y(:height)),
	Elements(Points(X, Y, Legend(1)), Smoother(X, Y, Legend(2))),
	By(:age),
	SendToByGroup({:age == 12}, SendToReport(Dispatch({}, "height", ScaleBox, {Min(46.2708484375), Max(64.6984984375), Inc(5), Minor Ticks(1)}))),
	SendToByGroup({:age == 13}, SendToReport(Dispatch({}, "height", ScaleBox, {Min(54), Max(66.3534322916667), Inc(2), Minor Ticks(0)}))),
	SendToByGroup({:age == 14}, SendToReport(Dispatch({}, "height", ScaleBox, {Min(58.1802560677083), Max(70.9932314583333), Inc(2), Minor Ticks(1)}))),
	SendToByGroup({:age == 15}, SendToReport(Dispatch({}, "height", ScaleBox, {Min(61), Max(66.5205305091258), Inc(1), Minor Ticks(0)}))),
	SendToByGroup({:age == 16}, SendToReport(Dispatch({}, "height", ScaleBox, {Min(57.1194704166667), Max(68.432), Inc(2), Minor Ticks(1)}))),
	SendToByGroup({:age == 17}, SendToReport(Dispatch({}, "height", ScaleBox, {Min(59.0567933224374), Max(69.0987213244912), Inc(2), Minor Ticks(1)})))
);
-Jarmo
jthi
Super User

Re: How to set different scale when I use "by"?

Here is one scripting solution when using By. Depending where you get the min/max and ref line values, I would most likely move those outside of the For Each loop.

Names Default To Here(1); 

dt = Open("$SAMPLE_DATA/Big Class.jmp");

gbs = dt << Graph Builder(
	SendToByGroup({:age == 12}),
	Size(525, 454),
	Show Control Panel(0),
	Variables(X(:weight), Y(:height)),
	Elements(Points(X, Y, Legend(1)), Smoother(X, Y, Legend(2))),
	By(:age)
);

For Each({gb}, gbs,
	rep = Report(gb);
	yaxis = rep[AxisBox(2)];
	gbtitle = rep[Outline Box(1)] << Get title;
	category = Word(-1, gbtitle, "=");
	If(Contains({"12", "14", "15", "16"}, category),
		minval = 50;
		maxval = 70;
		ref1 = 55;
		ref2 = 65;
		ref1title = "500%";
		ref2title = "1000%";
	, 	Contains({"13"}, category),
		minval = 0;
		maxval = 100;
		ref1 = 5;
		ref2 = 95;
		ref1title = "-20%";
		ref2title = "20%";
	);
	yaxis << Min(minval) << Max(maxval);
	yaxis << Add Ref Line(ref1, "Solid", "Medium Dark Red", ref1title, 1);
	yaxis << Add Ref Line(ref2, "Solid", "Medium Dark Red", ref2title, 1);	
);
-Jarmo

Re: How to set different scale when I use "by"?

You might be able to adapt @jthi's approach using XPath(). Send this message to Graph Builder like this:

xAxis = d_graph << XPath( "//AxisBox" );
xAxis[2::N Items(xAxis)::2] << Min( min ) << Max( max ) ...;

You should get a list of references to all the Axis display boxes. You want to address the X axes, the even-numbered items in the list. You can use the Index function to subscript the list and send the Axis messages to the list in a cascade. The list will distribute the messages to every item for you.

LT
LT
Level I

Re: How to set different scale when I use "by"?

Thanks @jthi  and @Mark_Bailey .