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

Adding Text with statistic summary and automatic positioning under box plot

Hi, I have created graph builder with generated script as follows:

Graph Builder(
	Transform Column( "Unit Number", Nominal, Formula( Char( :"Unit S/N"n ) ) ),
	Size( 570, 817 ),
	Show Legend( 0 ),
	Variables( X( :Unit Number ), Y( :Bounding_Circle_Diameter um ) ),
	Elements( Box Plot( X, Y, Legend( 6 ) ) ),
	Local Data Filter(
		Add Filter(
			columns( :Param Name ),
			Where( :Param Name == "Fuiyoh" ),
			Display( :Param Name, N Items( 3 ), "List Display" )
		)
	),
	SendToReport(
		Dispatch(
			{},
			"Bounding_Circle_Diameter um",
			ScaleBox,
			{Min( 1500 ), Max( 5000 ), Inc( 500 ), Minor Ticks( 1 )}
		),
		Dispatch(
			{},
			"graph title",
			TextEditBox,
			{Set Text( "Bounding_Circle_Diameter um (Fuiyoh)" ), Set Font Size( 20 )}
		),
		Dispatch( {}, "X title", TextEditBox, {Set Font Size( 18 )} ),
		Dispatch( {}, "Y title", TextEditBox, {Set Font Size( 18 )} ),
		Dispatch(
			{},
			"Graph Builder",
			FrameBox,
			{Reference Line Order( 6 ),
			Add Graphics Script(
				2,
				Description( "" ),
				Text( Center Justified, {0, 2150}, "Range: 44.4638" );
				Text( Center Justified, {0, 2050}, "Mean: 2288.48" );
				Text( Center Justified, {1, 2500}, "Range: 136.315" );
				Text( Center Justified, {1, 2400}, "Mean: 2681.81" );
				Text( Center Justified, {2, 2100}, "Range: 97.6151" );
				Text( Center Justified, {2, 2000}, "Mean: 2278.41" );
			)}
		)
	)
);

But the text and positions were created manually with hard coded values. As it can be seen the data is filtered with a certain column values. Is there any way I could replace those hard coded values with the statistics from the data respectively?
Text Y position -> from Min values of the data subset
Mean -> average value from data subset
range -> Max - Min from data subset

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
txnelson
Super User

Re: Adding Text with statistic summary and automatic positioning under box plot

There is a better methodology to use to add graphics output to a graph.  Take a look at the example script below to see how to dynamically determine where and what to display on a graph.

txnelson_0-1686148237919.png

Names Default To Here( 1 );
Open( "$SAMPLE_DATA/Big Class.jmp" );

// Create the graph
gb = Graph Builder(
	Size( 528, 456 ),
	Show Control Panel( 0 ),
	Variables( X( :weight ), Y( :height ) ),
	Elements( Points( X, Y, Legend( 3 ) ), Smoother( X, Y, Legend( 4 ) ) )
);

// Access the report output
rgb = gb << report;

// Add a graphics script to the report output
rgb[framebox( 1 )] << add graphics script(

// Find the parametrics of the displayed graph
	xMaxAxis = rgb[AxisBox( 1 )] << get max;
	xMinAxis = rgb[AxisBox( 1 )] << get min;
	yMaxAxis = rgb[AxisBox( 2 )] << get max;
	yMinAxis = rgb[AxisBox( 2 )] << get min;
	
	// Calculate the desired column stats
	heightMean = Col Mean( :height );
	heightRange = Col Max( :height ) - Col Min( :height );
	
	// Calculate the xy position on the graph to display the text
	pos = As List(
		Matrix( (xMinAxis + .1 * (xMaxAxis - xMinAxis)) |/ (yMaxAxis - .1 * (yMaxAxis - yMinaxis)) )
	);

	// Write out the text
	Text( Center Justified, pos, "Mean: " || Format( heightMean, "fixed dec", 7, , 2 ) );
	
	// Change the display position for the next line to be displayed
	pos[2] = pos[2] - .05 * (yMaxAxis - yMinaxis);
	
	// Write out the new line
	Text( Center Justified, pos, "Range: " || Format( heightMean, "fixed dec", 7, , 2 ) );
);

 

Jim

View solution in original post

3 REPLIES 3

Re: Adding Text with statistic summary and automatic positioning under box plot

The Caption element can automatically update the stats as the filter is applied, and it has a few options for where to place the stats.  If you are using JMP 17 one of the options is to place the stats in a table below the axis.  Retaining the custom placement would likely require that you implement a JSL row-state handler to compute and replace the stats via script.

 

danschikore_0-1686143485767.png

 

 

dt = Open("$SAMPLE_DATA/Big Class.jmp");
dt << Graph Builder(
	Size( 528, 464 ),
	Show Control Panel( 0 ),
	Variables( X( :age ), Y( :height ) ),
	Elements(
		Box Plot( X, Y, Legend( 6 ) ),
		Caption Box(
			X,
			Y,
			Legend( 7 ),
			Summary Statistic( "Mean" ),
			Summary Statistic 2( "Range" ),
			Location( "Axis Table" )
		)
	),
	Local Data Filter( Add Filter( columns( :sex ), Where( :sex == "M" ) ) )
);

 

 

txnelson
Super User

Re: Adding Text with statistic summary and automatic positioning under box plot

There is a better methodology to use to add graphics output to a graph.  Take a look at the example script below to see how to dynamically determine where and what to display on a graph.

txnelson_0-1686148237919.png

Names Default To Here( 1 );
Open( "$SAMPLE_DATA/Big Class.jmp" );

// Create the graph
gb = Graph Builder(
	Size( 528, 456 ),
	Show Control Panel( 0 ),
	Variables( X( :weight ), Y( :height ) ),
	Elements( Points( X, Y, Legend( 3 ) ), Smoother( X, Y, Legend( 4 ) ) )
);

// Access the report output
rgb = gb << report;

// Add a graphics script to the report output
rgb[framebox( 1 )] << add graphics script(

// Find the parametrics of the displayed graph
	xMaxAxis = rgb[AxisBox( 1 )] << get max;
	xMinAxis = rgb[AxisBox( 1 )] << get min;
	yMaxAxis = rgb[AxisBox( 2 )] << get max;
	yMinAxis = rgb[AxisBox( 2 )] << get min;
	
	// Calculate the desired column stats
	heightMean = Col Mean( :height );
	heightRange = Col Max( :height ) - Col Min( :height );
	
	// Calculate the xy position on the graph to display the text
	pos = As List(
		Matrix( (xMinAxis + .1 * (xMaxAxis - xMinAxis)) |/ (yMaxAxis - .1 * (yMaxAxis - yMinaxis)) )
	);

	// Write out the text
	Text( Center Justified, pos, "Mean: " || Format( heightMean, "fixed dec", 7, , 2 ) );
	
	// Change the display position for the next line to be displayed
	pos[2] = pos[2] - .05 * (yMaxAxis - yMinaxis);
	
	// Write out the new line
	Text( Center Justified, pos, "Range: " || Format( heightMean, "fixed dec", 7, , 2 ) );
);

 

Jim

Re: Adding Text with statistic summary and automatic positioning under box plot

A few points about using a graphics script:

  • The graphics script computation will occur at every refresh of the screen
  • The computation is not using the row-states, so it will still have issues with filters
  • If you save the script from the platform and rerun it later, it will not work because it is not self-contained.  This also affects saving in a Workflow, Project, Dashboard, or to a JRP file.