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

How to use variables in scale values (of a heat map)

Hi All, 

 

In the following example, a heat map was created using Big Class.jmp as an example:

 

gb=Graph Builder(
	Size( 686, 525 ),
	Show Control Panel( 0 ),
	Variables( X( :weight ), Y( :height ), Color( :age ) ),
	Elements( Heatmap( X, Y, Legend( 7 ) ) ),
	SendToReport(
		Dispatch(
			{},
			"400",
			ScaleBox,
			{Legend Model(
				7,
				Properties(
					0,
					{gradient( {Scale Values( [11 18] )} )},
					Item ID( "age", 1 )
				)
			)}
		)
	)
);

 Is there a way to use variables to define the gradient scale limits? Here's what I'd like to achieve:

 

 

gradient_low=10;
gradient_high=19;

gb=Graph Builder(
	Size( 686, 525 ),
	Show Control Panel( 0 ),
	Variables( X( :weight ), Y( :height ), Color( :age ) ),
	Elements( Heatmap( X, Y, Legend( 7 ) ) ),
	SendToReport(
		Dispatch(
			{},
			"400",
			ScaleBox,
			{Legend Model(
				7,
				Properties(
					0,
					{gradient( {Scale Values( matrix({gradient_low, gradient_high}) )} )},
					Item ID( "age", 1 )
				)
			)}
		)
	)
);

 

 

I would like to use "grandient_low" and "gradient_high" to define the heatmap gradient limits.

I've tried to use eval() , eval expr(), etc. but haven't got it to work yet. 

 

Thanks

 

5 REPLIES 5
jthi
Super User

Re: How to use variables in scale values (of a heat map)

You can

Names Default To Here(1); 

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

gradient_low = 10;
gradient_high = 19;

gb = Eval(EvalExpr(dt << Graph Builder(
	Size(686, 525),
	Show Control Panel(0),
	Variables(X(:weight), Y(:height), Color(:height)),
	Elements(Heatmap(X, Y, Legend(7))),
	SendToReport(
		Dispatch(
			{},
			"400",
			ScaleBox,
			{Legend Model(
				7,
				Properties(
					0,
					{gradient({Scale Values(Expr(Matrix({gradient_low, gradient_high})`))})},
					Item ID("height", 1)
				)
			)}
		)
	)
)));

but I would most likely go through Legend Server

Names Default To Here(1); 

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

gradient_low = 10;
gradient_high = 19;

gb = dt << Graph Builder(
	Size(686, 525),
	Show Control Panel(0),
	Variables(X(:weight), Y(:height), Color(:height)),
	Elements(Heatmap(X, Y, Legend(7))),
);

m_gradient = Matrix({gradient_low, gradient_high})`;

server = gb << Get Legend Server;
items = server << Get Legend Items;
items[1][1] << Set Properties({gradient({Scale Values(m_gradient)})});
-Jarmo
txnelson
Super User

Re: How to use variables in scale values (of a heat map)

@LatentDataTiger 

What Jarmo states is correct.  However, he has made a change to your example that may not be noticed.  Your example uses the variable Age as the Color column, where Jarmo has changed it to Height.  The difference is, that Age has a Modeling Type of Ordinal, and Height has a  Modeling Type of Continuous.  An ordinal column will not honor the Gradient values.  To do this for age, you need to change the Modeling Type of the column.  Here is a script that  sets the specified color gradient for your original example.

Names Default To Here( 1 );
dt = 
// Open Data Table: Big Class.jmp
// → Data Table( "Big Class" )
Open( "$SAMPLE_DATA/Big Class.jmp" );

dt:age << modeling type( continuous );

gradient_low = 10;
gradient_high = 19;

Eval(
	Eval Expr(
		gb = Graph Builder(
			Size( 686, 525 ),
			Show Control Panel( 0 ),
			Variables( X( :weight ), Y( :height ), Color( :age ) ),
			Elements( Heatmap( X, Y, Legend( 7 ) ) ),
			SendToReport(
				Dispatch(
					{},
					"400",
					ScaleBox,
					{Legend Model(
						7,
						Properties(
							0,
							{gradient(
								{Scale Values( Matrix( {Expr( gradient_low ), Expr( gradient_high )} ) )}
							)},
							Item ID( "age", 1 )
						)
					)}
				)
			)
		)
	)
)
;
Jim

Re: How to use variables in scale values (of a heat map)

Hi Jarmo and Jim

 

 

I'm very interesting in learning the legend server technique, but the last line of your script didn't work. Here's the error I get:

object not subscriptable in access or evaluation of 'items[1][1]' , items[1][/*###*/1]

Can you please help check the last line in

Names Default To Here(1); 

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

gradient_low = 10;
gradient_high = 19;

gb = dt << Graph Builder(
	Size(686, 525),
	Show Control Panel(0),
	Variables(X(:weight), Y(:height), Color(:height)),
	Elements(Heatmap(X, Y, Legend(7))),
);

m_gradient = Matrix({gradient_low, gradient_high});

server = gb << Get Legend Server;
items = server << Get Legend Items;
items[1][1] << Set Properties({gradient({Scale Values(m_gradient)})});

 

Thanks, 

rex

jthi
Super User

Re: How to use variables in scale values (of a heat map)

Could maybe be version related. Which JMP version are you using? I'm using JMP 17.2.

-Jarmo

Re: How to use variables in scale values (of a heat map)

I'm currently using JMP 15 and 16. I do have JMP 17, but some of my tool box that my colleagues developed wouldn't work in JMP17, so I decided to stay with 15 and 16.