- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
For loop Graph builder with reference line
Hi,
I want to write a script with for loop to generate Box plots with horizontal refernce lines and save it. I can do it in graph builder also but my dataset is huge so adding refernce line manually would take too much tim.
I have to two data table one to generate data table and other to generate refernce lines.
I want to have a loop to Box plot Player (in this case 'a' and 'b) on X-axis and column would switches for all games ('Badminton', 'Table Tennis', 'Lawn Tennis'). JMP script would also read one more file that contains refernce line and overlay refernce lines of particular game to that particular plot.
Please help to write a script for this requirement.
Thanks :)
Game | Refernce Line 1 | Refernce Line 2 |
Badminton | 7 | 1 |
Table Tennis | 8 | 2 |
Lawn Tennis | 6 | 3 |
Player | Zone | Badminton | Table Tennis | Lawn Tennis |
a | North | 2 | 2 | 3 |
a | North | 3 | 6 | 3 |
a | North | 4 | 6 | 5 |
a | North | 5 | 2 | 2 |
a | North | 2 | 5 | 6 |
a | North | 4 | 5 | 6 |
a | North | 4 | 3 | 6 |
a | North | 4 | 5 | 2 |
a | North | 9 | 7 | 6 |
a | North | 5 | 0 | 5 |
b | South | 1 | 3 | 7 |
b | South | 2 | 4 | 7 |
b | South | 4 | 7 | 8 |
b | South | 3 | 6 | 3 |
b | South | 6 | 4 | 5 |
b | South | 2 | 2 | 2 |
b | South | 5 | 8 | 6 |
b | South | 6 | 5 | 2 |
b | South | 7 | 2 | 3 |
b | South | 6 | 4 | 6 |
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: For loop Graph builder with reference line
Then a different approach would have to be used. Response Limits only support Lower, Middle and Upper.
Here is a simple script that works with the data tables you supplied, that will plot out all of the reference lines
Names Default To Here( 1 );
dtMain = Data Table( "Main" );
dtLimits = Data Table( "Limits" );
// Get the columns to create box plots for
boxPlotList = dtMain << get column names( string, numeric );
// Get the columns that contain limits
refLineList = dtLimits << get column names( string, numeric );
// Loop across the box plot columns and generate the box plots
For( i = 1, i <= N Items( boxPlotList ), i++,
ow = Oneway( Y( Column( boxPlotList[i] ) ), X( :Player ), Box Plots( 1 ) );
// Find out if any reference line references are specified for the current
// box plot column
refLineMatrix = dtLimits << get rows where( :game == boxPlotList[i] );
// If references are found, then loop across the columns and rows in the Limits table
// and add the reference lines
If( N Rows( refLineMatrix ) > 0,
For( refRow = 1, refRow <= N Rows( refLineMatrix ), refRow++,
For( refCol = 1, refCol <= N Items( refLineList ), refCol++,
refLineValue = Column( dtLimits, refLineList[refCol] )[refRow];
Report( ow )[AxisBox( 1 )] << Add Ref Line( refLineValue, "Solid", "Black", "", 1 );
)
)
);
);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: For loop Graph builder with reference line
I suggest that you just enter the values from your second data table as a "Response Limits" column property. If you do that, they will be displayed on the charts you are using automatically.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: For loop Graph builder with reference line
I didin't get how actually I will do add the data from second table as response limit.
Also, I have 2293 columns like that and this activity I have to do every week. So, its better to have ascript.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: For loop Graph builder with reference line
Here is a script that first creates the 2 data tables you displayed in your first entry, followed by the code that copies the limits from the limits table and applies them to each column in the main table
Names Default To Here( 1 );
dtMain = New Table( "Main",
Add Rows( 20 ),
New Column( "Player",
Character,
"Nominal",
Set Values(
{"a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "b", "b", "b", "b", "b", "b", "b", "b", "b", "b"}
)
),
New Column( "Zone",
Character,
"Nominal",
Set Values(
{"North", "North", "North", "North", "North", "North", "North", "North", "North", "North", "South",
"South", "South", "South", "South", "South", "South", "South", "South", "South"}
)
),
New Column( "Badminton",
Numeric,
"Continuous",
Format( "Best", 12 ),
Set Values( [2, 3, 4, 5, 2, 4, 4, 4, 9, 5, 1, 2, 4, 3, 6, 2, 5, 6, 7, 6] )
),
New Column( "Table Tennis",
Numeric,
"Continuous",
Format( "Best", 12 ),
Set Values( [2, 6, 6, 2, 5, 5, 3, 5, 7, 0, 3, 4, 7, 6, 4, 2, 8, 5, 2, 4] )
),
New Column( "Lawn Tennis",
Numeric,
"Continuous",
Format( "Best", 12 ),
Set Values( [3, 3, 5, 2, 6, 6, 6, 2, 6, 5, 7, 7, 8, 3, 5, 2, 6, 2, 3, 6] )
)
);
dtLimits = New Table( "Limits",
Add Rows( 3 ),
New Column( "Game",
Character,
"Nominal",
Set Values( {"Badminton", "Table Tennis", "Lawn Tennis"} ),
Set Display Width( 128 )
),
New Column( "Reference Line 1", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [7, 8, 6] ) ),
New Column( "Reference Line 2", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [1, 2, 3] ) )
);
// Here is the code that sets the Response Limits
For( i = 1, i <= N Rows( dtLimits ), i++,
If( Try( (Column( dtMain, (Column( dtLimits, "Game" )[i]) )) << get name, "" ) != "",
Eval(
Substitute(
Expr(
Column( dtMain, Column( dtLimits, "Game" )[i] ) << set property(
"response limits",
{Goal( Maximize ), Lower( __Low__, 1 ), Upper( __up__, 1 ), Importance( 1 ),
Show Limits( 1 )}
)
),
Expr( __Low__ ), dtLimits:Reference Line 2[i],
Expr( __Up__ ),
dtLimits:Reference Line 1[i]
)
)
)
);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: For loop Graph builder with reference line
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: For loop Graph builder with reference line
Then a different approach would have to be used. Response Limits only support Lower, Middle and Upper.
Here is a simple script that works with the data tables you supplied, that will plot out all of the reference lines
Names Default To Here( 1 );
dtMain = Data Table( "Main" );
dtLimits = Data Table( "Limits" );
// Get the columns to create box plots for
boxPlotList = dtMain << get column names( string, numeric );
// Get the columns that contain limits
refLineList = dtLimits << get column names( string, numeric );
// Loop across the box plot columns and generate the box plots
For( i = 1, i <= N Items( boxPlotList ), i++,
ow = Oneway( Y( Column( boxPlotList[i] ) ), X( :Player ), Box Plots( 1 ) );
// Find out if any reference line references are specified for the current
// box plot column
refLineMatrix = dtLimits << get rows where( :game == boxPlotList[i] );
// If references are found, then loop across the columns and rows in the Limits table
// and add the reference lines
If( N Rows( refLineMatrix ) > 0,
For( refRow = 1, refRow <= N Rows( refLineMatrix ), refRow++,
For( refCol = 1, refCol <= N Items( refLineList ), refCol++,
refLineValue = Column( dtLimits, refLineList[refCol] )[refRow];
Report( ow )[AxisBox( 1 )] << Add Ref Line( refLineValue, "Solid", "Black", "", 1 );
)
)
);
);