cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • Sign-in to the JMP Community will be unavailable intermittently Dec. 6-7 due to a system update. Thank you for your understanding!
  • We’re retiring the File Exchange at the end of this year. The JMP Marketplace is now your destination for add-ins and extensions.
  • JMP 19 is here! Learn more about the new features.

Discussions

Solve problems, and share tips and tricks with other JMP users.
Choose Language Hide Translation Bar
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
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
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
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

 

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

Recommended Articles