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
pzang
Level III

Match Line Color of Normal Quantile Plot to Row Color Set in Row Legend

In Oneway plot, I color the markers with the color theme "SAS Statistical" in Row Legend, but the lines connecting the markers in the Normal Quantile Plot still use "JMP Default" colors:  

 

Picture1.png

 

I can manually change the line colors to "SAS Statistical", by going to the "Legend Settings" and change the Color Theme to to "SAS Statistical".  However, this method actually hard-code the colors in the JSL as highlighted below, and I cannot use it as a generic solution.  For example, in a different dataset with four groups (1C, 2E, 3E and 4E), the line color of 4E is not defined.  Is there a generic way using JSL, to keep the line colors consistent with the row colors I set in Row Legend, regardless of how many groups I have?  Thanks.

 

Picture2.png

Oneway(
	Y( :Data ),
	X( :Group ),
	Plot Actual by Quantile( 1 ),
	Line of Fit( 0 ),
	Box Plots( 1 ),
	X Axis Proportional( 0 ),
	Points Jittered( 1 ),
	Grand Mean( 0 ),
	SendToReport(
		Dispatch(
			{},
			"222",
			ScaleBox,
			{Legend Model(
				1,
				Properties(
					0,
					{Line Color( -7306931 ), Fill Color( -7306931 )},
					Item ID( "1C", 1 )
				),
				Properties(
					1,
					{Line Color( -13654875 ), Fill Color( -13654875 )},
					Item ID( "2E", 1 )
				),
				Properties(
					2,
					{Line Color( -6727072 ), Fill Color( -6727072 )},
					Item ID( "3E", 1 )
				)
			)}
		),
		Dispatch(
			{},
			"Oneway Plot",
			FrameBox,
			{DispatchSeg( Box Plot Seg( 1 ), Line Color( "Red" ) ),
			DispatchSeg( Box Plot Seg( 2 ), Line Color( "Red" ) ),
			DispatchSeg( Box Plot Seg( 3 ), Line Color( "Red" ) ),
			Row Legend(
				Group,
				Color( 1 ),
				Color Theme( "SAS Statistical" ),
				Marker( 0 ),
				Marker Theme( "" ),
				Continuous Scale( 0 ),
				Reverse Scale( 0 ),
				Excluded Rows( 0 )
			)}
		)
	)
);
2 ACCEPTED SOLUTIONS

Accepted Solutions
txnelson
Super User

Re: Match Line Color of Normal Quantile Plot to Row Color Set in Row Legend

I think I have finally figured out your actual stated problem.....please forgive my thick headedness......

Here is a way to match the point colors with the line colors using a Color Theme.....in this case the SAS Statistical color theme

sasstat.PNG

Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/big class.jmp" );

// Set the row state colors
dt << color by column( :age , color theme("SAS Statistical"));

// Find out how many groupings there are
summarize( dt, grpBy = By( :age ) );

// Create the chart
ow = Oneway(
	Y( :height ),
	X( :age ),
	Plot Actual by Quantile( 1 ),
	Box Plots( 1 )
);

// Get the colors defined by the Color Theme
c = Get Color Theme Detail( "SAS Statistical" );

// Loop across the segments setting the lines to the required colors
For( i = 1, i <= N Items( grpBy ) * 2, i = i + 2,
	seg = (Report( ow )[FrameBox( 2 )] << Find Seg( Line Seg( i ) ));
	seg << line color( c[3][Ceiling( i / 2 )] );
);
Jim

View solution in original post

pzang
Level III

Re: Match Line Color of Normal Quantile Plot to Row Color Set in Row Legend

Slightly modified the script so I don't have to go back to dt to find the # of groups, and made it into a function for easier use.

 

SetNQPLineColor = function({ow,theme},
	{Default Local},
	
	// Get the colors defined by the Color Theme
	c = Get Color Theme Detail( eval(theme) );
	
	// Get the # of line segs
	ow_frmbx = ow << xpath("//FrameBox[@helpKey=\!"Oneway QuantilePlot\!"]");
	Nseg = ow_frmbx << segCount("Line Seg");
	Nseg=Nseg[1];
	
	// Loop across the segments setting the lines to the required colors
	For( i = 1, i <= Nseg, i+= 2,
		seg = ow_frmbx << Find Seg( Line Seg( i ) );
		seg << Line Color( c[3][Ceiling( i / 2 )] );
	);
	
	"Done!";
);


Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/big class.jmp" );

// Set the row state colors
dt << color by column( :age , color theme("SAS Statistical"));

// Create the chart
ow1 = Oneway(
	Y( :height ),
	X( :age ),
	Plot Actual by Quantile( 1 ),
	Box Plots( 1 )
);

SetNQPLineColor(ow1,"SAS Statistical");

Picture4.png

View solution in original post

9 REPLIES 9
txnelson
Super User

Re: Match Line Color of Normal Quantile Plot to Row Color Set in Row Legend

I believe you can get what you want by just setting the Row State colors for the rows, and then running your Oneway.

colorby.PNG

Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/big class.jmp" );

dt << color by column( :sex );
Oneway(
	Y( :height ),
	X( :sex ),
	Plot Actual by Quantile( 1 ),
	Box Plots( 1 ),
	SendToReport(
		Dispatch(
			{},
			"Oneway Plot",
			FrameBox,
			{DispatchSeg( Box Plot Seg( 1 ), Line Color( "Red" ) ), DispatchSeg(
				Box Plot Seg( 2 ),
				Line Color( "Red" )
			)}
		)
	)
);
Jim
pzang
Level III

Re: Match Line Color of Normal Quantile Plot to Row Color Set in Row Legend

@txnelson Thank you for your reply.  However, it doesn't work for color themes other than "JMP Default".

 

Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/big class.jmp" );

dt << color by column( :sex , color theme("SAS Statistical"));
Oneway(
	Y( :height ),
	X( :sex ),
	Plot Actual by Quantile( 1 ),
	Box Plots( 1 ),
	SendToReport(
		Dispatch(
			{},
			"Oneway Plot",
			FrameBox,
			{DispatchSeg( Box Plot Seg( 1 ), Line Color( "Red" ) ), DispatchSeg(
				Box Plot Seg( 2 ),
				Line Color( "Red" )
			)}
		)
	)
);

Picture3.png

txnelson
Super User

Re: Match Line Color of Normal Quantile Plot to Row Color Set in Row Legend

I think I have finally figured out your actual stated problem.....please forgive my thick headedness......

Here is a way to match the point colors with the line colors using a Color Theme.....in this case the SAS Statistical color theme

sasstat.PNG

Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/big class.jmp" );

// Set the row state colors
dt << color by column( :age , color theme("SAS Statistical"));

// Find out how many groupings there are
summarize( dt, grpBy = By( :age ) );

// Create the chart
ow = Oneway(
	Y( :height ),
	X( :age ),
	Plot Actual by Quantile( 1 ),
	Box Plots( 1 )
);

// Get the colors defined by the Color Theme
c = Get Color Theme Detail( "SAS Statistical" );

// Loop across the segments setting the lines to the required colors
For( i = 1, i <= N Items( grpBy ) * 2, i = i + 2,
	seg = (Report( ow )[FrameBox( 2 )] << Find Seg( Line Seg( i ) ));
	seg << line color( c[3][Ceiling( i / 2 )] );
);
Jim
pzang
Level III

Re: Match Line Color of Normal Quantile Plot to Row Color Set in Row Legend

@txnelson Thank you!  This works beautifully.

pzang
Level III

Re: Match Line Color of Normal Quantile Plot to Row Color Set in Row Legend

Slightly modified the script so I don't have to go back to dt to find the # of groups, and made it into a function for easier use.

 

SetNQPLineColor = function({ow,theme},
	{Default Local},
	
	// Get the colors defined by the Color Theme
	c = Get Color Theme Detail( eval(theme) );
	
	// Get the # of line segs
	ow_frmbx = ow << xpath("//FrameBox[@helpKey=\!"Oneway QuantilePlot\!"]");
	Nseg = ow_frmbx << segCount("Line Seg");
	Nseg=Nseg[1];
	
	// Loop across the segments setting the lines to the required colors
	For( i = 1, i <= Nseg, i+= 2,
		seg = ow_frmbx << Find Seg( Line Seg( i ) );
		seg << Line Color( c[3][Ceiling( i / 2 )] );
	);
	
	"Done!";
);


Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/big class.jmp" );

// Set the row state colors
dt << color by column( :age , color theme("SAS Statistical"));

// Create the chart
ow1 = Oneway(
	Y( :height ),
	X( :age ),
	Plot Actual by Quantile( 1 ),
	Box Plots( 1 )
);

SetNQPLineColor(ow1,"SAS Statistical");

Picture4.png

pzang
Level III

Re: Match Line Color of Normal Quantile Plot to Row Color Set in Row Legend

@txnelson A follow-up question:  if there are more than 12 groups, I get the following error, and line#13 becomes white:

 

Ceiling(i / 2) = 13;
Subscript Range in access or evaluation of 'c[3][Ceiling(i / 2)]' , c[3][/*###*/Ceiling( i / 2 )]

Picture6.png

 

 

It seems that "SAS Statistical" only has 12 colors defined:

 

 

 N Items(Eval List(Get Color Theme Detail("SAS Statistical")[3])) = 12;

So how does JMP handle it if there are more groups than the # of colors defined in the color theme?  For example, in the plot above group 13 has a marker color different from the other 12 groups.  How does JMP determine this color?  Thanks.

 

txnelson
Super User

Re: Match Line Color of Normal Quantile Plot to Row Color Set in Row Legend

Off hand I do not know.  I would look in the documentation, and/or run some tests, and find out what it does.  Another option is for you to take over all control of setting the colors, and for you to come up with your own coloring.

Jim
pzang
Level III

Re: Match Line Color of Normal Quantile Plot to Row Color Set in Row Legend

@txnelson Thank you for your suggestion.  I think I may have solved the problem.  If I only set the color of the first 12 groups and leave the rest as they are, it seems that JMP has an algorithm to generate their colors based on these 12 groups, and the generated colors match the row colors from "color by column":

 

Picture7.png

pzang
Level III

Re: Match Line Color of Normal Quantile Plot to Row Color Set in Row Legend

Forgot to post the updated JSL function:

 

SetNQPLineColor = function({ow,theme},
	{Default Local},
// Get the colors defined by the Color Theme c = Get Color Theme Detail( eval(theme) ); // Get the # of line segs ow_frmbx = ow << xpath("//FrameBox[@helpKey=\!"Oneway QuantilePlot\!"]"); Nseg = ow_frmbx << segCount("Line Seg"); Nseg=Nseg[1]; // Loop across the segments setting the lines to the required colors For( i = 1, i <= min( Nseg , 2 * N Items(Eval List(c[3])) ), i+= 2, seg = ow_frmbx << Find Seg( Line Seg( i ) ); seg << Line Color( c[3][Ceiling( i / 2 )] ); ); "Done"; );