cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Check out the JMP® Marketplace featured Capability Explorer add-in
Choose Language Hide Translation Bar
lisamaley
Level III

Locked Columns are messing up script

I teach Outlier Box plots and wrote a script to add the entire length of the whisker so I can visually show my class how the whiskers are calculated.   The script works great unless my columns are locked.    Why would locking the columns impact my script?  After the script runs I saved the script to a script window and it is correct, but it will not draw out the whiskers on some groups.   Here is my script, I am still working on it, I am using JMP Pro 17.0.0 on a MacBook:

 

Names Default To Here( 0 );

Clear Log();

dt = Current Data Table();


If( Not( Is Scriptable( dt ) ), 
	// Check that there is a data set open;
	//	ca=Caption("Please Open Design Data Set", Back Color(yellow));
	//	Stop();
	dtsel = Pick File( "Open File", {"JMP|jmp", "All files|*"} );
	If( dtsel == "",
		Stop(),
		Try( dt = Open( dtsel ), Stop() )
	);
);


output = Expr(

	dt2 = Data Table( dt ) << Summary(
		Group( bycol ),
		Median( nm ),
		Interquartile Range( nm ),
		Quantiles( 25, nm ),
		Quantiles( 75, nm ),
		Freq( "None" ),
		Weight( "None" ),
		Link to original data table( 0 )
	);
	
	columnnamemedian = Column( dt2, 3 ) << Get Name;
	columnnamesample = Column( dt2, 2 ) << Get Name;
	columnnamegroup = Column( dt2, 1 ) << Get Name;
	columnameIQR = Column( dt2, 4 ) << Get Name;
	columnname25 = Column( dt2, 5 ) << Get Name;
	columnname75 = Column( dt2, 6 ) << Get Name;

	Medians = Column( dt2, columnnamemedian ) << Get As Matrix;
	Samplesize = Column( dt2, columnnamesample ) << Get As Matrix;
	Groups = Column( dt2, columnnamegroup ) << Get As Matrix;
	IQR = Column( dt2, columnameIQR ) << Get As Matrix;
	Q25 = Column( dt2, columnname25 ) << Get As Matrix;
	Q75 = Column( dt2, columnname75 ) << Get As Matrix;
	
	meanno = N Rows( dt2 );
	
	LWhis = {};
	UWhis = {};
	

	
	i = 1;
	For( i = 1, i <= meanno, i++,
		LWhis[i] = Q25[i] - 1.5 * IQR[i];
		UWhis[i] = Q75[i] + 1.5 * IQR[i];
		
		
		
		Show( Q25[i] );
		Show( Q75[i] );
		Show( LWhis[i] );
		Show( UWhis[i] );
		Show( IQR[i] );
		Show( i );
		
		If( LWhis[i] > Q25[i],
			LWhis[i] = Q25[i],
			LWhis[i] = LWhis[i]
			
		);
		If( UWhis[i] < Q75[i],
			UWhis[i] = Q75[i],
			UWhis[i] = UWhis[i]
			
		);
		

	);
	
	MinLW = LWhis[1];
	MaxUW = UWhis[1];
	i = 1;
	
	For( i = 1, i <= meanno, i++,
		If( LWhis[i] < MinLW,
			MinLW = LWhis[i],
			MinLW = MinLW
		);
		
		If( UWhis[i] > MaxUW,
			MaxUW = UWhis[i],
			MaxUW = MaxUW
		);
	);
	
	
	If( MinLW < 0,
		MinLW = MinLW * 1.1,
		MinLW = MinLW * 0.9
		
	);

	If( MaxUW < 0,
		MaxUW = MaxUW * 0.9,
		MaxUW = MaxUW * 1.1
		
	);
	
	Current Data Table( dt );
	//Close(dt2, NoSave);

		
	gb = Graph Builder(
		Variables( X( (Column( bycol )) ), Y( Column( nm ) ) ),
		Elements( Points( X, Y ), Box Plot( X, Y ) ), 

		SendToReport(
			Dispatch( {} ), 
			
			
		), 
	
	);

	gbr = gb << report;
	Report( gb )[AxisBox( 2 )] << Max( MaxUW ) << Min( MinLW );
	
	i = 1;
	For( i = 1, i <= meanno, i++, 
	
		Show( LWhis[i] );
		Show( UWhis[i] );
		Eval(
			Eval Expr(
				gbr[Framebox( 1 )] << Add graphics Script(
		
					Pen Color( Red );
					Line Style( "Dotted" );
					V Line( Expr( i ), Expr( LWhis[i] ), Expr( Q25[i] ) );
					V Line( Expr( i ), Expr( Q75[i] ), Expr( UWhis[i] ) );
					
				);
				
			)
		)

		;
	);
	
	
	

	//dt2 << Minimize  Window;
	

	Close( dt2, Nosave  );			
		
);

w = New Window( "Variables",
	<<Modal,
	<<Bring Window to Front,
	Border Box( top( 20 ), bottom( 20 ), Left( 20 ), Right( 20 ),
		V List Box( // V and H lists nest to organize the display boxes
			Text Box(
				"Enter the Variables for the Calculations:",
				<<horizontal alignment( "Left" ), 

			), 
			
			Spacer Box( size( 1, 30 ) ),
			Border Box( Left( 3 ), top( 2 ), 
			
				V List Box(
					H List Box(
						Panel Box( "Columns", colListData = Col List Box( All, width( 130 ), nLines( 10 ) ) ), 
					
						V List Box(
							Panel Box( "Selected Columns",
								Lineup Box( N Col( 2 ), Spacing( 3 ),
									Button Box( "Column to Analyze",
										colListW << Append( colListData << GetSelected )
									),
									colListW = Col List Box( width( 130 ), nLines( 1 ), MinItems( 1 ) ), 
								
									Button Box( "Grouped by", colby << Append( colListData << GetSelected ) ),
									colby = Col List Box( width( 130 ), nLines( 1 ), MinItems( 0 ) ), 

								), 

							), 

						),
						Panel Box( "Action",
							Lineup Box( N Col( 1 ),
								Button Box( "OK",
									nm = colListW << Get Items;
									bycol = colby << Get Items;

									nitemsby = N Items( bycol );
		
									Eval( output );
									<<Close Window;
								
								),
								Button Box( "Cancel", 

								),
								Text Box( " " ),
								Button Box( "Remove", colListW << RemoveSelected ), 

							)
						)
					),
					
				)
			), 
 
			
			
		)
	)
);
1 ACCEPTED SOLUTION

Accepted Solutions
jthi
Super User

Re: Locked Columns are messing up script

The lines are shifted by one (I think with Nominal/ordinal data X-axis starts from 0

jthi_0-1695926446551.png

jthi_1-1695926467773.png

You can modify this part of your script

For(i = 1, i <= meanno, i++, 
	Show(LWhis[i]);
	Show(UWhis[i]);
	Eval(
		Eval Expr(
			gbr[Framebox(1)] << Add graphics Script(
				Pen Color(Red);
				Line Style("Dotted");
				V Line(Expr(i), Expr(LWhis[i]), Expr(Q25[i]));
				V Line(Expr(i), Expr(Q75[i]), Expr(UWhis[i]));		
			);
		)
	);
);

Easiest is most likely to add i-1 inside the V Line(Expr()).

-Jarmo

View solution in original post

5 REPLIES 5
jthi
Super User

Re: Locked Columns are messing up script

Could you provide some examples? Images or dataset where it happens. Not sure why locked columns would affect graphic script, but you might have to modify the "index" of lines to start from 0 instead of 1

(1 and 2)

jthi_0-1695913829201.png

(0 and 1)

jthi_1-1695913886287.png

 

-Jarmo
lisamaley
Level III

Re: Locked Columns are messing up script

lisamaley_0-1695916889579.png

The first one has no lines drawn, but when I look at the script for this one, it shows that it should have them.  number 7 as a gap and 3 is wrong, here is the script for this exact plot, notice the red lines are not lining up with what is drawn. I have attached my  JMP file that I used for this.:

 

Graph Builder(
	Variables( X( :Process Configuration ), Y( :Y ) ),
	Elements( Points( X, Y, Legend( 1 ) ), Box Plot( X, Y, Legend( 2 ) ) ),
	SendToReport(
		Dispatch(
			{},
			"Y",
			ScaleBox,
			{Min( 6.36165 ), Max( 36.07175 ), Inc( 5 ), Minor Ticks( 1 )}
		),
		Dispatch(
			{},
			"Graph Builder",
			FrameBox,
			{Add Graphics Script(
				13,
				Description( "" ),
				Pen Color( Red );
				Line Style( "Dotted" );
				V Line( 1, 13.039, 18.502 );
				V Line( 1, 22.144, 27.607 );
			), Add Graphics Script(
				14,
				Description( "" ),
				Pen Color( Red );
				Line Style( "Dotted" );
				V Line( 2, 7.0685, 16.061 );
				V Line( 2, 22.056, 31.0485 );
			), Add Graphics Script(
				15,
				Description( "" ),
				Pen Color( Red );
				Line Style( "Dotted" );
				V Line( 3, 11.772, 17.973 );
				V Line( 3, 22.107, 28.308 );
			), Add Graphics Script(
				16,
				Description( "" ),
				Pen Color( Red );
				Line Style( "Dotted" );
				V Line( 4, 14.0465, 18.737 );
				V Line( 4, 21.864, 26.5545 );
			), Add Graphics Script(
				17,
				Description( "" ),
				Pen Color( Red );
				Line Style( "Dotted" );
				V Line( 5, 13.529, 18.002 );
				V Line( 5, 20.984, 25.457 );
			), Add Graphics Script(
				18,
				Description( "" ),
				Pen Color( Red );
				Line Style( "Dotted" );
				V Line( 6, 8.0605, 17.335 );
				V Line( 6, 23.518, 32.7925 );
			), Add Graphics Script(
				19,
				Description( "" ),
				Pen Color( Red );
				Line Style( "Dotted" );
				V Line( 7, 16.3455, 19.356 );
				V Line( 7, 21.363, 24.3735 );
			)}
		)
	)
);
lisamaley
Level III

Re: Locked Columns are messing up script

If I copy the table I sent you into a new table without locked columns it works.   How do you modify the "index" of the line?  I have other files with locked columns and they do not work either.

jthi
Super User

Re: Locked Columns are messing up script

The lines are shifted by one (I think with Nominal/ordinal data X-axis starts from 0

jthi_0-1695926446551.png

jthi_1-1695926467773.png

You can modify this part of your script

For(i = 1, i <= meanno, i++, 
	Show(LWhis[i]);
	Show(UWhis[i]);
	Eval(
		Eval Expr(
			gbr[Framebox(1)] << Add graphics Script(
				Pen Color(Red);
				Line Style("Dotted");
				V Line(Expr(i), Expr(LWhis[i]), Expr(Q25[i]));
				V Line(Expr(i), Expr(Q75[i]), Expr(UWhis[i]));		
			);
		)
	);
);

Easiest is most likely to add i-1 inside the V Line(Expr()).

-Jarmo
lisamaley
Level III

Re: Locked Columns are messing up script

I did try changing my nominal column to numeric/continuous to see if it would work and it did not.  The only thing that would work was copying it into another table, so that it why I assumed it was the locked columns.   I am not sure why it did not work, but when I added an if statement to look for whether or not the modeling type was nominal or continuous and added your suggestion, it did work.  So I am still confused, but got it working.  Thank you!  I do not think I would have figured that out since I did try to convert it to numeric/continuous and it did not work.