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
jasongao
Level II

how to sort x axis by another column value

For example, I have 3 column:

Name Age Score:

Jason  21 98

Alice 19 67

Dave 36 89

John 28 70

I would like to plot x:  Name and Y: Score, but I also want to sort X axis (names) by their Age. 

Thanks so much for the help!  

1 ACCEPTED SOLUTION

Accepted Solutions
txnelson
Super User

Re: how to sort x axis by another column value

When using Graph Builder, all that has to be done, is to drag the variable you want to order your axis by, to the Order By area for the Axis, as shown below

order.PNG

Or you can sort the data table by the sort variable(Age), and then set the Column Property, Row Order Levels for the column Name, and then the order used for the Name variable axis will be the order the Names are found in the data table.

Jim

View solution in original post

7 REPLIES 7
txnelson
Super User

Re: how to sort x axis by another column value

When using Graph Builder, all that has to be done, is to drag the variable you want to order your axis by, to the Order By area for the Axis, as shown below

order.PNG

Or you can sort the data table by the sort variable(Age), and then set the Column Property, Row Order Levels for the column Name, and then the order used for the Name variable axis will be the order the Names are found in the data table.

Jim
jasongao
Level II

Re: how to sort x axis by another column value

Thanks! It works! 

ms
Super User (Alumni) ms
Super User (Alumni)

Re: how to sort x axis by another column value

I think the column property "Value Ordering" is what you need. It can be set manually using the column dialog or with jsl (example below).

 

// Example Table
New Table("test",
    Add Rows(4),
    New Column("Name",
    Character,
        Set Values({"Jason", "Alice", "Dave", "John"})
    ),
    New Column("Age",
        Set Values([21, 19, 36, 28])
    ),
    New Column("Score:",
        Set Values([98, 67, 89, 70])
    )
);
// Plot Score by Age
Oneway(Y(:Name("Score:")), X(:Name));

// Set value ordering to Name after mean Age
Summarize( g = by( :Name ), m = Mean( :Age ) );
:Name << Set Property( "Value Ordering", Eval( g[Rank Index( m )] ) );

// Plot again!
Oneway(Y(:Name("Score:")), X(:Name));
AdamChoen
Level IV

Re: how to sort x axis by another column value

Hi Guys,

 

Any idea how I can use ms suggestion by group?
for the above example, let's say I like to chart the oneway by gander.

 

I can do this with graph builder but I like to use the Variability Chart.

 

Oneway(Y(:Name("Score:")), X(:Name), By(:Name("Gander"));
//With Graph Builder

Graph Builder(
Size( 800, 500),
Variables(
X( :name, Order By( :age, Ascending, Order Statistic( "Mean" ) ),

....

Group X( :Gender, N View Levels( 2 ), First View Level( 2 ) ),

...

 

Thanks, Adam
ms
Super User (Alumni) ms
Super User (Alumni)

Re: how to sort x axis by another column value

Not sure I understand what you need, but the same approach can be used for Variability Chart. If grouped by an additional variable, the value ordering should be correctly applied within each group.

 

Here's an example based on the Big Class example table:

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

// Set value ordering to :name after mean :age
Summarize( g = by( :name ), m = Mean( :age ) );
:Name << Set Property( "Value Ordering", Eval( g[Rank Index( m )] ) );

// Variability chart with names grouped by sex ordered after age
Variability Chart(Y(:height), X(:sex, :name));
AdamChoen
Level IV

Re: how to sort x axis by another column value

Sorry, the Sex group example is not so good since it has few (or no) similar names on each group.

 

here is the same example based on the semiconductor table:

dt = Open("$SAMPLE_DATA/Semiconductor Capability.jmp");

// Set value ordering to :name after mean :age
Summarize( g = by( :lot_id ), m = Mean( :PNP1 ) );
:lot_id << Set Property( "Value Ordering", Eval( g[Rank Index( m )] ) );

// Variability chart with names grouped by sex ordered after age
Variability Chart(Y(:NPN1), X(:SITE, :lot_id));

it results with the below Var chart (all SITE has same lot_id order) - which is wrong I believe.


How can I plot the lot_id order by PNP1 for every SITE in Var chart using jsl.
Hope I made my request clearer. 

 

I prefer using 

Variability Chart(Y(:NPN1), X(:SITE), By (:lot_id));

and not

Variability Chart(Y(:NPN1), X(:SITE, :lot_id));

Also, the statement that I can do this using graph builder from my previous replay here is wrong, I see that now.

 

Thank you.

 

Image 173.png

AdamChoen_0-1638823052051.png

 

 

Thanks, Adam
AdamChoen
Level IV

Re: how to sort x axis by another column value

I think creating a concat column will do the trick as follow

 

dt = Open("$SAMPLE_DATA/Semiconductor Capability.jmp");

dt << New Column("lotID by Site", Character, Formula(char(:SITE)||"_"||:lot_id) );

// Set value ordering to :name after mean :age
Summarize( g = by( :Name("lotID by Site") ), m = Mean( :PNP1 ) );
:Name("lotID by Site")  << Set Property( "Value Ordering", Eval( g[Rank Index( m )] ) );

// Variability chart with names grouped by sex ordered after age
Variability Chart(Y(:NPN1), X(:Name("lotID by Site")), by (:SITE));

if anyone can share a more elegant solution I will appreciate it.

 

Thanks, Adam