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

[Script] Color Gradient Output

R1=(dt<< Tabulate(
Show Control Panel( 0 ),
Show Tooltip( 1 ),
Add Table(
Column Table( Statistics( N )),
Column Table( Grouping Columns( :Name( "TEST" ) ), Statistics( Row %, N )),
Row Table( Grouping Columns( :Radius ) )
)
)) << Make Into Data Table;

R1:"N(1)"<< Set Property( "Color Gradient", {"White to Orange", Range( {0, 547, 187.945945945946} )} )
<< Color Cell by Value;
R1:"N(8)"<< Set Property( "Color Gradient", {"White to Orange", Range( {0, 547, 187.945945945946} )} )
<< Color Cell by Value;

R1:"N(9)"<< Set Property( "Color Gradient", {"White to Orange", Range( {0, 547, 187.945945945946} )} )
<< Color Cell by Value;

 

The output of the script above is combined together. Therefore the colour gradient that is set for N(1), N(8), N(9) has combined, how do i seperate each N(s) to have their own specific colour gradient

1 ACCEPTED SOLUTION

Accepted Solutions
txnelson
Super User

Re: [Script] Color Gradient Output

The script fails because there is not a column defined called:

     Zero to Three 3

The log issues the following error

Scoped data table access requires a data table column or variable in access or evaluation of 'dt:zero to three 3' , dt:zero to three 3/*###*/

This can be handled in several ways.  If you want to continue using "Hard Coding" you can overcome the issue with the "Try" function:

Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA\big class.jmp" );
dt << New Column( "zero to three", formula( Random Integer( 0, 3 ) ) );
dt << New Column( "zero to three 2", formula( Random Integer( 0, 3 ) ) );
dt << New Column( "zero to three 4", formula( Random Integer( 0, 3 ) ) );
Try( dt:zero to three << Set Property( "Color Gradient", {"White to Orange"} ) << Color Cell by Value );
Try( dt:zero to three 2 << Set Property( "Color Gradient", {"White to Orange"} ) << Color Cell by Value );
Try( dt:zero to three 3 << Set Property( "Color Gradient", {"White to Orange"} ) << Color Cell by Value );
Try( dt:zero to three 4 << Set Property( "Color Gradient", {"White to Orange"} ) << Color Cell by Value );

Or, you can get a little more advanced and look and see if what names match the pattern you want, and if it does match it, then apply the color gradient:

Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA\big class.jmp" );
dt << New Column( "zero to three", formula( Random Integer( 0, 3 ) ) );
dt << New Column( "zero to three 2", formula( Random Integer( 0, 3 ) ) );
dt << New Column( "zero to three 4", formula( Random Integer( 0, 3 ) ) );
ColNames = dt << get column names( string, numeric );
For( i = 1, i <= N Items( ColNames ), i++,
	If( Contains( Uppercase( ColNames[i] ), "ZERO TO THREE" ) == 1,
		Column( dt, ColNames[i] ) << Set Property( "Color Gradient", {"White to Orange"} ) << Color Cell by Value
	)
);

Is this the issue you are trying to work around?

 

Jim

View solution in original post

10 REPLIES 10
txnelson
Super User

Re: [Script] Color Gradient Output

Can you provide the R1 data table?

Jim
kuanaunwei
Level III

Re: [Script] Color Gradient Output

Hi, the attachment is the R1 data table

 

txnelson
Super User

Re: [Script] Color Gradient Output

I hope this is what you are asking for.

To change the color pattern, all you have to do is to change the Gradient Pattern and/or the color range.  Below I have taken the first column N(1) and changed it's gradient

R1:"N(1)" << Set Property( "Color Gradient", {"Blue to Green to Red", Range( {31, 284, 150} )} ) << Color Cell by Value;
R1:"N(8)" << Set Property( "Color Gradient", {"White to Orange", Range( {0, 547, 187.945945945946} )} ) << Color Cell by Value;
R1:"N(9)" << Set Property( "Color Gradient", {"White to Orange", Range( {0, 547, 187.945945945946} )} ) << Color Cell by Value;
Jim
kuanaunwei
Level III

Re: [Script] Color Gradient Output

Hi, 

 

Well I am doing it this way, but as the data size increases to N(99), all columns would not apply the colour patterns. 

 

Is there another way to apply the colour patterns?

txnelson
Super User

Re: [Script] Color Gradient Output

Can you please explain why going above 99 columns would be a limitation?  I don't understand your comment.

Jim
kuanaunwei
Level III

Re: [Script] Color Gradient Output

This is run with the given scriptThis is run with the given scriptThis is the type colour gradient that i am talking aboutThis is the type colour gradient that i am talking about

 

I would like the output from picture 2

txnelson
Super User

Re: [Script] Color Gradient Output

I must be missing something, because the color gradient, and the specified range you can control.  So I don't see why there is an issue with the colors not being set as you desire.  Below is an example of letting the coloring being set by JMP evalueating the range of the values, and a second example of you setting the values.

These values can be set by calculating the column means, or whatever method you want

Names default to here(1);
dt=open("$SAMPLE_DATA\big class.jmp");
dt<<new column("zero to three", formula(random integer(0,3)));
dt<<new column("zero to three 2", formula(random integer(0,3)));
dt:zero to three << Set Property( "Color Gradient", {"White to Orange"} ) << Color Cell by Value;
dt:zero to three 2 << Set Property( "Color Gradient", {"White to Orange",Range( {0,3,1.5} )}) << Color Cell by Value;

Now, if you want to explicitly set a color to a specific cell, then you can do that.  

Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
:Age << Color Cells( "Red",5 );
Jim
kuanaunwei
Level III

Re: [Script] Color Gradient Output

Ok, I have understood the problem of my script. Try running this.

Names default to here(1);
dt=open("$SAMPLE_DATA\big class.jmp");
dt<<new column("zero to three", formula(random integer(0,3)));
dt<<new column("zero to three 2", formula(random integer(0,3)));
dt<<new column("zero to three 4, formula(random integer(0,3))); dt:zero to three << Set Property( "Color Gradient", {"White to Orange"} ) << Color Cell by Value; dt:zero to three 2 << Set Property( "Color Gradient", {"White to Orange"}) << Color Cell by Value;
dt:zero to three 3 << Set Property( "Color Gradient", {"White to Orange"}) << Color Cell by Value;
dt:zero to three 4 << Set Property( "Color Gradient", {"White to Orange"}) << Color Cell by Value

 

txnelson
Super User

Re: [Script] Color Gradient Output

The script fails because there is not a column defined called:

     Zero to Three 3

The log issues the following error

Scoped data table access requires a data table column or variable in access or evaluation of 'dt:zero to three 3' , dt:zero to three 3/*###*/

This can be handled in several ways.  If you want to continue using "Hard Coding" you can overcome the issue with the "Try" function:

Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA\big class.jmp" );
dt << New Column( "zero to three", formula( Random Integer( 0, 3 ) ) );
dt << New Column( "zero to three 2", formula( Random Integer( 0, 3 ) ) );
dt << New Column( "zero to three 4", formula( Random Integer( 0, 3 ) ) );
Try( dt:zero to three << Set Property( "Color Gradient", {"White to Orange"} ) << Color Cell by Value );
Try( dt:zero to three 2 << Set Property( "Color Gradient", {"White to Orange"} ) << Color Cell by Value );
Try( dt:zero to three 3 << Set Property( "Color Gradient", {"White to Orange"} ) << Color Cell by Value );
Try( dt:zero to three 4 << Set Property( "Color Gradient", {"White to Orange"} ) << Color Cell by Value );

Or, you can get a little more advanced and look and see if what names match the pattern you want, and if it does match it, then apply the color gradient:

Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA\big class.jmp" );
dt << New Column( "zero to three", formula( Random Integer( 0, 3 ) ) );
dt << New Column( "zero to three 2", formula( Random Integer( 0, 3 ) ) );
dt << New Column( "zero to three 4", formula( Random Integer( 0, 3 ) ) );
ColNames = dt << get column names( string, numeric );
For( i = 1, i <= N Items( ColNames ), i++,
	If( Contains( Uppercase( ColNames[i] ), "ZERO TO THREE" ) == 1,
		Column( dt, ColNames[i] ) << Set Property( "Color Gradient", {"White to Orange"} ) << Color Cell by Value
	)
);

Is this the issue you are trying to work around?

 

Jim