BookmarkSubscribe
Choose Language Hide Translation Bar
jasongao
Contributor

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!  

0 Kudos
1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
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
3 REPLIES 3
Highlighted
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
Contributor

Re: how to sort x axis by another column value

Thanks! It works! 

0 Kudos
ms
Super User ms
Super User

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));