Subscribe Bookmark RSS Feed

How to insert data labels in graph builder

BemRan

Occasional Contributor

Joined:

Nov 3, 2016

Can someone please tell me how to insert data labels in Confidence interval plots and control chart averages of Jmp12? See the attached image for better clarification.

 

Confidence.png

1 ACCEPTED SOLUTION

Accepted Solutions
txnelson

Super User

Joined:

Jun 22, 2012

Solution

Here is the simple script to give you a start.  It can be made far more fancy, but this should give you a start:

Names Default To Here( 1 );
dt = Current Data Table();

// Calculate the means so they can be displayed
Summarize( dt, bygroup = by( :Name( "Factor-1" ) ), themeans = Mean( :thickness ) );

// Run the basic graph builder code
gb = dt << Graph Builder(
	Variables( X( :Name( "Factor-1" ) ), Y( :Thickness ) ),
	Elements( Points( X, Y, Legend( 5 ), Summary Statistic( "Mean" ), Error Bars( "Confidence Interval" ) ) )
);

// Loop across the different factors and add the mean as a text
// Note, that because the x axis values are based upon a character column,
// the X position is 0 for the first group, 1 for the second, etc.
For( i = 1, i <= N Items( bygroup ), i++, 
	Eval(
		Substitute(
				Expr(
					Report( gb )[framebox( 1 )] << add graphics script( Text( {__x__, __y__}, __mean__ ) )
				),
			Expr( __x__ ), i-1 + .1,
			Expr( __y__ ), themeans[i],
			Expr( __mean__ ), Char( Themeans[i] )
		)
	)
);
Jim
8 REPLIES
txnelson

Super User

Joined:

Jun 22, 2012

Are you asking how to interactively add labels to the chart?

Since the Mean and Confidence Intervals are calculated values, you can not use the Row State Label options to display the values. You can right click on the graph, and add a caption box, however, the stats displayed there are overall stats. What you will need to do is to go to the Drawing tools and select a text entry box, and to add it manually to the graph.

Graph Label.png

Jim
BemRan

Occasional Contributor

Joined:

Nov 3, 2016

Thanks Jim.

It looks like that I have to manually calculate stat for each factor and insert in a caption box!

txnelson

Super User

Joined:

Jun 22, 2012

A script can be written to handle that issue.  The summary stats can be calculated and then annotation can be added to the graph that contains the summary information

 

If you have some sample data I can give you a good start on how to do that.

Jim
BemRan

Occasional Contributor

Joined:

Nov 3, 2016

Thanks! I have attached a simple two factor data table.
BemRan

Occasional Contributor

Joined:

Nov 3, 2016

txnelson

Super User

Joined:

Jun 22, 2012

My fault.....there is an issue with the current discussion forum, where you can not attach something after the initial responses. Can you convert it to a script:

 

Under the "Source" entry in the Tables Panel for the data table, click on it and select

     "Copy Table Script" 
Then click on the "Insert JSL Code" in your reply and paste the code into it

Jim
BemRan

Occasional Contributor

Joined:

Nov 3, 2016

New Table( "test",
	Add Rows( 20 ),
	New Column( "Factor-1",
		Character,
		"Nominal",
		Set Values(
			{"Factor 1", "Factor 1", "Factor 1", "Factor 1", "Factor 1", "Factor 1",
			"Factor 1", "Factor 1", "Factor 1", "Factor 1", "Factor 2", "Factor 2",
			"Factor 2", "Factor 2", "Factor 2", "Factor 2", "Factor 2", "Factor 2",
			"Factor 2", "Factor 2"}
		)
	),
	New Column( "Thickness",
		Numeric,
		"Continuous",
		Format( "Best", 11 ),
		Set Selected,
		Set Values(
			[1.50740933, 1.601142469, 1.074704843, 1.884292315, 1.012608931,
			1.607336196, 1.832731982, 1.269104476, 1.652280427, 1.729379409,
			0.195244429, 0.764830482, 0.401538929, 0.890074236, 0.395640352,
			0.896762654, 0.389728401, 0.223935429, 0.165762602, 0.414394237]
		)
	),
	Set Row States( [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] )
)
txnelson

Super User

Joined:

Jun 22, 2012

Solution

Here is the simple script to give you a start.  It can be made far more fancy, but this should give you a start:

Names Default To Here( 1 );
dt = Current Data Table();

// Calculate the means so they can be displayed
Summarize( dt, bygroup = by( :Name( "Factor-1" ) ), themeans = Mean( :thickness ) );

// Run the basic graph builder code
gb = dt << Graph Builder(
	Variables( X( :Name( "Factor-1" ) ), Y( :Thickness ) ),
	Elements( Points( X, Y, Legend( 5 ), Summary Statistic( "Mean" ), Error Bars( "Confidence Interval" ) ) )
);

// Loop across the different factors and add the mean as a text
// Note, that because the x axis values are based upon a character column,
// the X position is 0 for the first group, 1 for the second, etc.
For( i = 1, i <= N Items( bygroup ), i++, 
	Eval(
		Substitute(
				Expr(
					Report( gb )[framebox( 1 )] << add graphics script( Text( {__x__, __y__}, __mean__ ) )
				),
			Expr( __x__ ), i-1 + .1,
			Expr( __y__ ), themeans[i],
			Expr( __mean__ ), Char( Themeans[i] )
		)
	)
);
Jim