Share your ideas for the JMP Scripting Unsession at Discovery Summit by September 17th. We hope to see you there!
Choose Language Hide Translation Bar
Highlighted
Song
Level III

How can i reference line change? no numeric

Hi I want to put the Std mean of the two data into the reference line as shown in the graph below.

The JMP script below has I arbitrarily written the Std mean, 13.2 (22.2+4.2)/2 = 13.2

Actually the data I use is more than two. (Below image is just example)

How can i script change?

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


Graph Builder(
	Size( 1056, 825 ),
	Variables( Y( :height ), Y( :weight ) ),
	Elements(
		Position( 1, 1 ),
		Points( Y, Legend( 7 ) ),
		Caption Box( Y, Legend( 13 ), Summary Statistic( "Std Dev" ) )
	),
	Elements(
		Position( 1, 2 ),
		Points( Y, Legend( 8 ) ),
		Caption Box( Y, Legend( 14 ), Summary Statistic( "Std Dev" ) )
	),
	SendToReport(
		Dispatch(
			{},
			"height",
			ScaleBox,
			{Add Ref Line( 13.3, "Solid", "Medium Dark Red", "Std Dev mean", 2 )}
		),
		Dispatch(
			{},
			"weight",
			ScaleBox,
			{Add Ref Line( 13.3, "Solid", "Medium Dark Red", "Std Dev mean", 2 )}
		)
	)
);

image.png

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
txnelson
Super User

Re: How can i reference line change? no numeric

As can be seen in my previous response, to Add a Reference Line, all you have to do, is to pass an << Add Ref Line message to the Axis that you want to add the reference line to:

Report( gb )[AxisBox( 2 )] << Add Ref Line( Col Std Dev( :Height ), "Solid", "Medium Dark Red", "Std Dev mean", 2 );

To find out which Axis to properly point to, one needs to look into the Tree Structure of the output from the Graph Builder.  To do this, you right click on the grey triangle next to the Graph Builder Heading and select

     Edit==>Show Tree Structure

tree1.PNG

tree2.PNG

Then you can align the Graph Window with the Tree Structure Window, and click on the item in the Graph Window that you want to see the Tree Structure for, and JMP will move to that structure in the Tree Structure Window

 

tree3.PNG

As can be seen here, the Axis for the Height column, for Sex=="F" is AxisBox(2)

If you click on each of the Axes in question you will see what Axis Box to point to to Add a Ref Line to.  The last axis of question, column Weight, for Sex=="M" is:

tree4.PNG

Now all that needs to be done is to expand on the JSL to create the Reference Lines for all 4 axes and to calculate in each of the Add Ref Line messages, the correct value for the placement of the Reference Line.  Here are the 4 Add Ref Line lines of code:

 
Report( gb )[AxisBox( 3 )] << Add Ref Line(
	Col Std Dev( If( :sex == "F", :Weight, . ) ),
	"Solid",
	"Medium Dark Red",
	"Std Dev mean",
	2
);
Report( gb )[AxisBox( 2 )] << Add Ref Line(
	Col Std Dev( If( :sex == "M", :Height, . ) ),
	"Solid",
	"Medium Dark Red",
	"Std Dev mean",
	2
);
Report( gb )[AxisBox( 3 )] << Add Ref Line(
	Col Std Dev( If( :sex == "M", :Weight, . ) ),
	"Solid",
	"Medium Dark Red",
	"Std Dev mean",
	2
);

Note that in this case, that the Sex column had to be taken into account for the calculation of the Standard Deviation, along with the measurement column.

Jim

View solution in original post

7 REPLIES 7
Highlighted
txnelson
Super User

Re: How can i reference line change? no numeric

Here is a simple modification to your script that draws a reference line at the value of the Std Dev for each column(:Height,:Weight)

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


gb=Graph Builder(
	Size( 1056, 825 ),
	Variables( Y( :height ), Y( :weight ) ),
	Elements(
		Position( 1, 1 ),
		Points( Y, Legend( 7 ) ),
		Caption Box( Y, Legend( 13 ), Summary Statistic( "Std Dev" ) )
	),
	Elements(
		Position( 1, 2 ),
		Points( Y, Legend( 8 ) ),
		Caption Box( Y, Legend( 14 ), Summary Statistic( "Std Dev" ) )
	)
	);
report(gb)[AxisBox(2)]<<Add Ref Line( col std dev(:Height), "Solid", "Medium Dark Red", "Std Dev mean",2  );	
report(gb)[AxisBox(3)]<<Add Ref Line( col std dev(:Weight), "Solid", "Medium Dark Red", "Std Dev mean", 2 );
Jim
Highlighted
Song
Level III

Re: How can i reference line change? no numeric

Highlighted
txnelson
Super User

Re: How can i reference line change? no numeric

As can be seen in my previous response, to Add a Reference Line, all you have to do, is to pass an << Add Ref Line message to the Axis that you want to add the reference line to:

Report( gb )[AxisBox( 2 )] << Add Ref Line( Col Std Dev( :Height ), "Solid", "Medium Dark Red", "Std Dev mean", 2 );

To find out which Axis to properly point to, one needs to look into the Tree Structure of the output from the Graph Builder.  To do this, you right click on the grey triangle next to the Graph Builder Heading and select

     Edit==>Show Tree Structure

tree1.PNG

tree2.PNG

Then you can align the Graph Window with the Tree Structure Window, and click on the item in the Graph Window that you want to see the Tree Structure for, and JMP will move to that structure in the Tree Structure Window

 

tree3.PNG

As can be seen here, the Axis for the Height column, for Sex=="F" is AxisBox(2)

If you click on each of the Axes in question you will see what Axis Box to point to to Add a Ref Line to.  The last axis of question, column Weight, for Sex=="M" is:

tree4.PNG

Now all that needs to be done is to expand on the JSL to create the Reference Lines for all 4 axes and to calculate in each of the Add Ref Line messages, the correct value for the placement of the Reference Line.  Here are the 4 Add Ref Line lines of code:

 
Report( gb )[AxisBox( 3 )] << Add Ref Line(
	Col Std Dev( If( :sex == "F", :Weight, . ) ),
	"Solid",
	"Medium Dark Red",
	"Std Dev mean",
	2
);
Report( gb )[AxisBox( 2 )] << Add Ref Line(
	Col Std Dev( If( :sex == "M", :Height, . ) ),
	"Solid",
	"Medium Dark Red",
	"Std Dev mean",
	2
);
Report( gb )[AxisBox( 3 )] << Add Ref Line(
	Col Std Dev( If( :sex == "M", :Weight, . ) ),
	"Solid",
	"Medium Dark Red",
	"Std Dev mean",
	2
);

Note that in this case, that the Sex column had to be taken into account for the calculation of the Standard Deviation, along with the measurement column.

Jim

View solution in original post

Highlighted
Song
Level III

Re: How can i reference line change? no numeric

@txnelson 

Thanks for your reply.

In the script below, all STD values in Group F are written as Group M STD values.

How can we separate them into two groups?

 

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


gb = Graph Builder(
	Size( 1056, 825 ),
	Variables( Y( :height ), Y( :weight ), Group Y( :sex ) ),
	Elements(
		Position( 1, 1 ),
		Points( Y, Legend( 7 ) ),
		Caption Box( Y, Legend( 13 ), Summary Statistic( "Std Dev" ) )
	),
	Elements(
		Position( 1, 2 ),
		Points( Y, Legend( 8 ) ),
		Caption Box( Y, Legend( 14 ), Summary Statistic( "Std Dev" ) )
	)
);

Report( gb )[AxisBox( 2 )] << Add Ref Line(
	Col Std Dev( If( :sex == "F", :Height, . ) ),
	"Solid",
	"Medium Dark Red",
	"Std Dev mean",
	2
);

Report( gb )[AxisBox( 3 )] << Add Ref Line(
	Col Std Dev( If( :sex == "F", :Height, . ) ),
	"Solid",
	"Medium Dark Red",
	"Std Dev mean",
	2
);
Report( gb )[AxisBox( 4 )] << Add Ref Line(
	Col Std Dev( If( :sex == "M", :Height, . ) ),
	"Solid",
	"Medium Dark Red",
	"Std Dev mean",
	2
);
Report( gb )[AxisBox( 5 )] << Add Ref Line(
	Col Std Dev( If( :sex == "M", :Weight, . ) ),
	"Solid",
	"Medium Dark Red",
	"Std Dev mean",
	2
);
Highlighted
txnelson
Super User

Re: How can i reference line change? no numeric

I see the issue you are pointing out.  It appears that even though the Display Tree indicates there are 4 separate Axes, JMP  actually treats them as just 2 axes.  Therefore, what has to be done to get as close to what you want as I think I can, one can take the data for Height and Weight into 4 columns,  based upon the Sex value, and then plot the 4 variables separately.

fourvars.PNG

Here is the JSL

names default to here(1);
dt = Open( "$SAMPLE_DATA/Big Class.jmp" ) ;

dtSplit = dt << Split(
	Split By( :sex ),
	Split( :height, :weight ),
	Remaining Columns( Drop All ),
	Sort by Column Property
);

gb = dtSplit << Graph Builder(
	Variables( Y( :height F ), Y( :weight F ), Y( :height M ), Y( :weight M ) ),
	Elements(
		Position( 1, 1 ),
		Points( Y, Legend( 11 ) ),
		Caption Box( Y, Legend( 15 ), Summary Statistic( "Std Dev" ) )
	),
	Elements(
		Position( 1, 2 ),
		Points( Y, Legend( 12 ) ),
		Caption Box( Y, Legend( 16 ), Summary Statistic( "Std Dev" ) )
	),
	Elements(
		Position( 1, 3 ),
		Caption Box( Y, Legend( 17 ), Summary Statistic( "Std Dev" ) ),
		Points( Y, Legend( 18 ) )
	),
	Elements(
		Position( 1, 4 ),
		Points( Y, Legend( 14 ) ),
		Caption Box( Y, Legend( 19 ), Summary Statistic( "Std Err" ) )
	),
	SendToReport(
		Dispatch(
			{},
			"weight F",
			ScaleBox,
			{Min( 49.5141101773061 ), Max( 150.319351489306 ), Inc( 20 ),
			Minor Ticks( 0 )}
		),
		Dispatch(
			{},
			"400",
			ScaleBox,
			{Legend Model(
				18,
				Properties( 0, {Line Color( 21 )}, Item ID( "height M", 1 ) )
			), Legend Model(
				14,
				Properties( 0, {Line Color( 19 )}, Item ID( "weight M", 1 ) )
			)}
		),
		Dispatch(
			{},
			"400",
			LegendBox,
			{Legend Position( {11, [0], 12, [1], 18, [3], 14, [2]} ),
			Position( {0, 1, 3, 2} )}
		)
	)
);

Report( gb )[AxisBox( 2 )] << Add Ref Line(
	Col Std Dev( :Height F ),
	"Solid",
	"Medium Dark Red",
	"Std Dev mean",
	2
);

Report( gb )[AxisBox( 3 )] << Add Ref Line(
	Col Std Dev( :Weight F),
	"Solid",
	"Medium Dark Red",
	"Std Dev mean",
	2
);
Report( gb )[AxisBox( 4 )] << Add Ref Line(
	Col Std Dev( :Height M ),
	"Solid",
	"Medium Dark Red",
	"Std Dev mean",
	2
);
Report( gb )[AxisBox( 5 )] << Add Ref Line(
	Col Std Dev( :Weight M ),
	"Solid",
	"Medium Dark Red",
	"Std Dev mean",
	2
);
Jim
Highlighted
Song
Level III

Re: How can i reference line change? no numeric

@txnelson 

Thanks for your kindly reply!

I have one more last! question.

sorry to bothering you..

 

I'd like to add the ref line Max, min (Mean + 4 * Std dev) in the all grouop(age).

problem is below script not work..

names default to here(1);
dt = Open( "$SAMPLE_DATA/Big Class.jmp" ) ;



gb = Graph Builder(
	Size( 1056, 825 ),
	Variables( X( :height ), Group Y( :age ) ),
	Elements(
		Bar( X, Legend( 17 ) ),
		Caption Box( X, Legend( 15 ), Response Axis( "X" ) ),
		Caption Box(
			X,
			Legend( 16 ),
			Response Axis( "X" ),
			Summary Statistic( "Std Dev" )
		)
	)
);


Report( gb )[AxisBox( 1 )] << Add Ref Line(
	Col Mean( :height ) + 4*Col Std Dev( :height ),
	"Solid",
	"Medium Dark Red",
	"Std Dev mean",
	2
);

and the other problem, how can i extract Max, Min (Mean + 4 * Std dev) all the group(age).

I'd like to apply the ref line Max (Mean + 4 * Std dev), Min (Mean + 4 * Std dev) all group same.

I think i can use Max(), Min() function... 

Highlighted
txnelson
Super User

Re: How can i reference line change? no numeric

Here is the method that I use to capture the column stats for a given subgroup, such as Age, and you are using.

colmin.PNG

Here is the script.  Just add the additional reference lines that you want using the same methodology

names default to here(1);
dt = Open( "$SAMPLE_DATA/Big Class.jmp" ) ;



gb = Graph Builder(
	Size( 1056, 825 ),
	Variables( X( :height ), Group Y( :age ) ),
	Elements(
		Bar( X, Legend( 17 ) ),
		Caption Box( X, Legend( 15 ), Response Axis( "X" ) ),
		Caption Box(
			X,
			Legend( 16 ),
			Response Axis( "X" ),
			Summary Statistic( "Std Dev" )
		)
	)
);


Report( gb )[AxisBox( 1 )] << Add Ref Line(
	Col Mean( if(:age == 12,:height,.) ) + 4*Col Std Dev( If(:age==12,:height,) ),
	"Solid",
	"Medium Dark Red",
	"Std Dev mean 12",
	2
);
Report( gb )[AxisBox( 1 )] << Add Ref Line(
	Col Min( if(:age == 12,:height,.) ),
	"Solid",
	"Medium Dark Red",
	"Min 12",
	2
);
Report( gb )[AxisBox( 1 )] << Add Ref Line(
	Col Max( if(:age == 12,:height,.) ),
	"Solid",
	"Medium Dark Red",
	"Max 12",
	2
);

Report( gb )[AxisBox( 1 )] << Add Ref Line(
	Col Mean( if(:age == 13,:height,.) ) + 4*Col Std Dev( If(:age==13,:height,) ),
	"Solid",
	"Medium Dark Red",
	"Std Dev mean 13",
	2
);
Jim
Article Labels

    There are no labels assigned to this post.