みなさんこんにちは
列の大きなリストがあり、それをループして、列リストの各列ごとに二変量グラフを作成します。 x 軸は毎回同じままです。
私も同じカテゴリ列でグループ化しています。ただし、その列のグループ/カテゴリの数は毎回変わります。
カテゴリがいくつあるかわからない場合、二変量プロットで「Fit Where」機能を使用して、各列のすべてのカテゴリを 1 つのグラフで表示するにはどうすればよいですか?
一般的に私は自分が望むものを作るためにこれを行います。
Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/Fishing.jmp" );
bivNew = dt << Bivariate(
Y( :Fish Caught ),
X( :People ),
Automatic Recalc( 1 ),
Fit Where( :Validation == 1, Fit Spline( 1, {Line Color( {212, 73, 88} )} ) ),
Fit Where( :Validation == 2, Fit Spline( 1, {Line Color( {66, 112, 221} )} ) )
);
しかし、ここでは、検証列の各カテゴリのグループ化 (Fit Where) をハードコードしています。自動化ソリューションのスクリプト作成に関して、検証列にカテゴリがいくつあるかわからない場合、どうすれば同じ出力を得ることができますか。
ご協力いただければ幸いです。
これは有効な方法の 1 つです。私は個人的に JMP のビルトイン スプラインを使用していません。これは、追加されたコントロール ボックスによって視覚的に乱雑になるためです。
Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/Fishing.jmp" );
Try( dt << Delete Columns( "GROUPING" ) );
dt << New Column( "GROUPING", "Character",
<<SET each="" value=""></SET>
これを行うにはさまざまな方法がありますが、簡単な方法の 1 つは、関連する関数を保持する小さな名前空間を使用することです。
関数/デフォルト設定を保持するライブラリは次のとおりです。
New Namespace( "bivar" );
bivar:default settings = [=>];
bivar:default settings["x size"] = 600;
bivar:default settings["y size"] = 400;
bivar:default settings["lambda"] = 1;
bivar:default settings["standardize splines"] = 1;
bivar:default settings["unselected line width"] = 4;
bivar:default settings["line width"] = 4;
bivar:default settings["selected line width"] = 5;
bivar:default settings["marker size"] = 4;
bivar:default settings["outline lines"] = 1;
bivar:default settings["fade unselected lines"] = 1;
bivar:default settings["spline points"] = 128;
<BR /><BR />//this is the only function that a user needs to call
bivar:plot = Function( {table, x column, y column, categorical column, title = "", settings = bivar:default settings},
{Default Local},
columns = table << Get Column Names();
If( Not( Contains( columns, As Name( x column ) ) ),
Throw( "Unable to find column \!"" || x column || "\!"" );
);
If( Not( Contains( columns, As Name( y column ) ) ),
Throw( "Unable to find column \!"" || y column || "\!"" );
);
If( Not( Contains( columns, As Name( categorical column ) ) ),
Throw( "Unable to find column \!"" || categorical column || "\!"" );
);
If( Column( table, x column ) << Get Data Type != "Numeric",
Throw( "X column must be Numeric" );
);
If( Column( table, y column ) << Get Data Type != "Numeric",
Throw( "Y column must be Numeric" );
);
If( Column( table, categorical column ) << Get Data Type != "Character",
Throw( "Legend column must be Character" );
);
table << Color or Mark by Column( categorical column );
olb = Outline Box( "",
Platform( table,
Bivariate(
X( Column( table, x column ) ),
Y( Column( table, y column ) ),
Dispatch(
{}, "Bivar Plot", Frame Box,
{
Frame Size( settings["x size"], settings["y size"] ), Marker Size( settings["marker size"] )
,
Row Legend( Column( table, categorical column ), Marker( 1 ), Continuous Scale( 0 ), Reverse Scale( 0 ), Excluded Rows( 0 ) )
}
)
)
)
);
If( title != "",
olb[Outline Box( 2 )] << Set Title( title )
);
bivar:add splines( table, olb[Frame Box( 1 )], olb[String Col Box( 1 )], x column, y column, categorical column, settings );
olb
);
bivar:add splines = Function( {table, frame box, legend box, x column, y column, categorical column, settings = bivar:default settings},
{Default Local},
sub table = table << Summary( Group( categorical column ), Link to Original Data Table( 0 ), Private );
colors = [=>];
For Each Row( sub table,
colors[Column( 1 )[]] = Color Of( Row State() )
);
legend values = Column( sub table, 1 ) << Get Values;
Close( sub table, No Save );
splines = [=>];
splines["__items__"] = legend values;
splines["__settings__"] = settings;
splines["__colors__"] = colors;
Summation( i = 1, N Items( legend values ),
item = legend values[i];
splines[item] = [=>];
Eval( Parse( Eval Insert( JSL Quote(
rows = table << Get Rows Where( !Excluded( Row State() ) & :Name("^categorical column^") == "^item^" & !Is Missing( :Name("^x column^") ) & !Is Missing( :Name("^y column^") ) )
) ) ) );
ordinate = Column( table, y column )[rows];
abcissa = Column( table, x column )[rows];
If( N Rows( rows ) > 3 & Min( abcissa ) != Max( abcissa ),
If( settings["standardize splines"],
x mean = Mean( abcissa );
x std dev = Std Dev( abcissa );
abcissa = (abcissa - x mean) / x std dev
);
x values = Min( abcissa )::Max( abcissa )::((Max( abcissa ) - Min( abcissa )) / settings["spline points"]);
spline values = Spline Eval( x values, Spline Coef( abcissa, ordinate, settings["lambda"] ) );
If( settings["standardize splines"],
x values = x std dev * x values + x mean
);
,
x values = abcissa;
spline values = ordinate
);
splines[item]["x"] = x values;
splines[item]["y"] = spline values;
;0
);
Eval( Eval Expr(
frame box << Add Graphics Script(
"CUSTOM_SPLINES";
Local( {splines = Expr( splines ), legend = Expr( legend box ), settings = Expr( settings ), selected, i, items, item, selected items},
selected = legend << Get Selected Rows;
If( N Rows( selected ) == 0,
Summation( i = 1, N Items( splines["__items__"] ),
item = splines["__items__"][i];
Transparency( 1 );
If( splines["__settings__"]["outline lines"],
Pen Color( "Black" );
Pen Size( splines["__settings__"]["line width"] + 1 );
Line( splines[item]["x"], splines[item]["y"] )
);
Pen Color( splines["__colors__"][item] );
Pen Size( splines["__settings__"]["line width"] );
Line( splines[item]["x"], splines[item]["y"] );
;0
)
,
selected items = splines["__items__"][selected];
Summation( i = 1, N Items( splines["__items__"] ),
item = splines["__items__"][i];
If( Not( Contains( selected items, item ) ),
If( settings["fade unselected lines"],
Transparency( 1 - Arg( Arg( Get Preferences( Graph Marker Unselected Fade ), 1 ), 1 ) / 100 )
,
Transparency( 1 )
);
Pen Color( splines["__colors__"][item] );
Pen Size( splines["__settings__"]["unselected line width"] );
Line( splines[item]["x"], splines[item]["y"] );
);
;0
);
Summation( i = 1, N Items( splines["__items__"] ),
item = splines["__items__"][i];
If( Contains( selected items, item ),
Transparency( 1 );
If( splines["__settings__"]["outline lines"],
Pen Color( "Black" );
Pen Size( splines["__settings__"]["selected line width"] + 1 );
Line( splines[item]["x"], splines[item]["y"] )
);
Pen Color( splines["__colors__"][item] );
Pen Size( splines["__settings__"]["selected line width"] );
Line( splines[item]["x"], splines[item]["y"] );
);
;0
)
);
items = splines["__items__"]
)
)
) )
);
0ライブラリを少なくとも 1 回実行した後 (たとえば、アドインの開始スクリプトに追加する)、ライブラリを非常に簡単に使用できるようになります。
Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
dt2 = Open( "$SAMPLE_DATA/Reliability/Adhesive Bond.jmp" );
dt3 = Open( "$SAMPLE_DATA/Cars.jmp" );
settings = bivar:default settings;
settings["outline lines"] = 0;
New Window( "test",
V List Box(
bivar:plot( dt3, "year", "wt", "make" )
,
bivar:plot( dt3, "year", "wt", "make", "Custom Title", settings ) // show how to change settings
,
bivar:plot( dt, "Height", "weight", "sex" )
,
bivar:plot( dt2, "weeks", "strength", "censor" )
)
)
これで煩わしいコントロール ボックスはなくなり、マーカーの選択モードと一致するようになりました (「未選択フェード」マーカー選択モードになっていると仮定)

お役に立てれば。
本当にありがとうございます。本当に役に立ちました。
ただし、この関数は単一の x 列と y 列に対しては機能するようです。同じ x 列とグループ化列を持つ y 列のリストを渡すと機能しません。列のグループに対して機能するように更新する必要があります。
この件に関してご協力いただき、改めて感謝申し上げます。