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:
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!
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 ] ) ) );
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] ) ) );
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:
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 ] ) ) );