Subscribe Bookmark RSS Feed

Reverse continuous group Y variable of graph builder

Tzu-Chun

Occasional Contributor

Joined:

Oct 25, 2017

Usually, we can reverse the X and Y axis in the axis settings -> Reverse order. However, it does not work for "Group" variable, especially of continuous type.

 

Here is an example

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

// Method 1 ... didn't work
// Column(dt, "weight")<<Set Property( "Axis", {Reversed Scale} );

// Method 2 ... didn't work
// List=sort descending(as list(Column(dt, "weight")<<get values))
// Column(dt, "weight")<<Set Property( "Value Ordering", List);

//Plot
Graph Builder(
    Size( 564, 540 ),
    Show Control Panel( 0 ),
    Variables( X( :sex ), Y( :height ), Group Y( :weight, levels(3) ) ),
    Elements( Points( X, Y, Legend( 2 ) ) ),
);

image.png

 

The "Weight" variable ploted interval of small values on the top and large values in the bottom, but it make more sense to me if the large one be placed on the top like Y-axis. Two different methods have been applied, but all of them didn't work in my case.

 

Method 1:

    Set the column property "Axis" in reverse order

 

Method 2:

    Set the column property "Value Ordering" in reverse order. In this way, JMP treated the continuous variable as discrete variable in the graph which is not the desired plot.

 

Any ideas?

1 ACCEPTED SOLUTION

Accepted Solutions
txnelson

Super User

Joined:

Jun 22, 2012

Solution

The approach I took to solve this problem is to create a new column that has a reversed value and then it applies a Value Label to label the groupings correctly.

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

// Method 1 ... didn't work
// Column(dt, "weight")<<Set Property( "Axis", {Reversed Scale} );

// Method 2 ... didn't work
// List=sort descending(as list(Column(dt, "weight")<<get values))
// Column(dt, "weight")<<Set Property( "Value Ordering", List);

dt << New Column( "New Weight",
	ordinal,
	formula(
		If(
			:weight <= Floor( Col Quantile( :weight, .333 ) + 1 ), 3,
			:Weight <= Floor( Col Quantile( :weight, .666 ) + 1 ), 2,
			1
		)
	)
);
Eval(
	Substitute(
			Expr(
				dt:new weight << set property( "value labels", {3 = _3_, 2 = _2_, 1 = _1_} )
			),
		Expr( _3_ ),
			Char( Min( dt:weight[dt << get rows where( :New Weight == 3 )] ) ) || "-" ||
			Char( Max( dt:weight[dt << get rows where( :New Weight == 3 )] ) ),
		Expr( _2_ ),
			Char( Max( dt:weight[dt << get rows where( :New Weight == 3 )] ) ) || "-" ||
			Char( Max( dt:weight[dt << get rows where( :New Weight == 2 )] ) ),
		Expr( _1_ ),
			Char( Max( dt:weight[dt << get rows where( :New Weight == 2 )] ) ) || "-" ||
			Char( Max( dt:weight[dt << get rows where( :New Weight == 1 )] ) )
	)
);
//Plot
Graph Builder(
	Size( 564, 540 ),
	Show Control Panel( 0 ),
	Variables( X( :sex ), Y( :height ), Group Y( :New Weight, levels( 3 ) ) ),
	Elements( Points( X, Y, Legend( 2 ) ) ),

);

reverse.PNG

The code is pretty basic, but will work for data where you want it grouped into 3 bins.  It could be expanded to allow for any number of levels.

Jim
2 REPLIES
txnelson

Super User

Joined:

Jun 22, 2012

Solution

The approach I took to solve this problem is to create a new column that has a reversed value and then it applies a Value Label to label the groupings correctly.

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

// Method 1 ... didn't work
// Column(dt, "weight")<<Set Property( "Axis", {Reversed Scale} );

// Method 2 ... didn't work
// List=sort descending(as list(Column(dt, "weight")<<get values))
// Column(dt, "weight")<<Set Property( "Value Ordering", List);

dt << New Column( "New Weight",
	ordinal,
	formula(
		If(
			:weight <= Floor( Col Quantile( :weight, .333 ) + 1 ), 3,
			:Weight <= Floor( Col Quantile( :weight, .666 ) + 1 ), 2,
			1
		)
	)
);
Eval(
	Substitute(
			Expr(
				dt:new weight << set property( "value labels", {3 = _3_, 2 = _2_, 1 = _1_} )
			),
		Expr( _3_ ),
			Char( Min( dt:weight[dt << get rows where( :New Weight == 3 )] ) ) || "-" ||
			Char( Max( dt:weight[dt << get rows where( :New Weight == 3 )] ) ),
		Expr( _2_ ),
			Char( Max( dt:weight[dt << get rows where( :New Weight == 3 )] ) ) || "-" ||
			Char( Max( dt:weight[dt << get rows where( :New Weight == 2 )] ) ),
		Expr( _1_ ),
			Char( Max( dt:weight[dt << get rows where( :New Weight == 2 )] ) ) || "-" ||
			Char( Max( dt:weight[dt << get rows where( :New Weight == 1 )] ) )
	)
);
//Plot
Graph Builder(
	Size( 564, 540 ),
	Show Control Panel( 0 ),
	Variables( X( :sex ), Y( :height ), Group Y( :New Weight, levels( 3 ) ) ),
	Elements( Points( X, Y, Legend( 2 ) ) ),

);

reverse.PNG

The code is pretty basic, but will work for data where you want it grouped into 3 bins.  It could be expanded to allow for any number of levels.

Jim
Tzu-Chun

Occasional Contributor

Joined:

Oct 25, 2017

Hi Jim, thanks so much for the help. that's really helpful and exactly what I need.