Share your ideas for the JMP Scripting Unsession at Discovery Summit by September 17th. We hope to see you there!
Choose Language Hide Translation Bar
Highlighted
vistacc
Level III

How to write a script to use a specific row for plot bar chart?

Hi all!

 

I want to plot a bar chart using a specific row in the data table. The format of the table is as following:photo.png

 

I am not sure what is the best way to do it.

My thought is to select the row, save it to a new data table, transpose the new table and then use the two columns in the new data table to plot the bar. The script for this method is a little bit long so I would like to know whether there is a more simple way for it.

 

Any help will be greatly appreciated!

 

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
txnelson
Super User

Re: How to write a script to use a specific row for plot bar chart?

The "values( dt[0, 5] )" refers to the values to be placed into the data table.  The "dt[0,5]" referred to the 5th row in the data table.  It actually was an error in my code, it should have been, "values( dt[5, 0] )".  The "0" refers to all columns in the data table.  I have changed my code below to meet the new requirement.

Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/blood pressure.jmp" );
dt << delete columns( 1, 2 );

rowNum = 5;

colNames = dt << get column names(string);


dt2 = New Table( "example",
	New Column( "Label", character, values( colNames ) ),
	New Column( "Row " || char( rowNum ), values( dt[rowNum, 0 ] ) ) );
Jim

View solution in original post

3 REPLIES 3
Highlighted
txnelson
Super User

Re: How to write a script to use a specific row for plot bar chart?

Here is a simple example of one way to do what you want

Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/blood pressure.jmp" );
dt << delete columns( 1, 2 );


dt2 = New Table( "example", New Column( "transpose", values( dt[0, 5] ) ) );
Jim
Highlighted
vistacc
Level III

Re: How to write a script to use a specific row for plot bar chart?

Thank you for your reply, Jim!
I don't get what "values( dt[0, 5] )" means here though. How can I just select the row that I want for the plot? For example, in my case, I only want to select row 132 as numeric values in y-axis for the plot and the names of the columns as the categorical names in the x-axis. Expected plot is as the following: figure.png

 

Highlighted
txnelson
Super User

Re: How to write a script to use a specific row for plot bar chart?

The "values( dt[0, 5] )" refers to the values to be placed into the data table.  The "dt[0,5]" referred to the 5th row in the data table.  It actually was an error in my code, it should have been, "values( dt[5, 0] )".  The "0" refers to all columns in the data table.  I have changed my code below to meet the new requirement.

Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/blood pressure.jmp" );
dt << delete columns( 1, 2 );

rowNum = 5;

colNames = dt << get column names(string);


dt2 = New Table( "example",
	New Column( "Label", character, values( colNames ) ),
	New Column( "Row " || char( rowNum ), values( dt[rowNum, 0 ] ) ) );
Jim

View solution in original post

Article Labels

    There are no labels assigned to this post.