我正在尝试使用循环重新创建下面的脚本(此脚本有效,但我希望它作为循环运行,以便它以相同的方式处理每个数据集):
bivariate(
Y( :name( "1st Thickness PST" ) ),
X( :site ),
By( :Lot ),
Fit Where( :Slot_id == 1, Fit Each Value( {Line Color( {213, 72, 87} )} ) ),
Fit Where( :Slot_id == 2, Fit Each Value( {Line Color( {57, 177, 67} )} ) ),
Fit Where( :Slot_id == 3, Fit Each Value( {Line Color( {64, 111, 223} )} ) ),
Fit Where( :Slot_id == 4, Fit Each Value( {Line Color( {207, 121, 38} )} ) ),
Fit Where( :Slot_id == 5, Fit Each Value( {Line Color( {33, 189, 145} )} ) ),
Fit Where( :Slot_id == 6, Fit Each Value( {Line Color( {161, 44, 220} )} ) ),
Fit Where( :Slot_id == 7, Fit Each Value( {Line Color( {200, 193, 39} )} ) ),
Fit Where( :Slot_id == 8, Fit Each Value( {Line Color( {31, 182, 182} )} ) ),
Fit Where( :Slot_id == 9, Fit Each Value( {Line Color( {201, 37, 205} )} ) ),
Fit Where( :Slot_id == 10, Fit Each Value( {Line Color( {145, 183, 32} )} ) ),
Fit Where( :Slot_id == 11, Fit Each Value( {Line Color( {35, 157, 195} )} ) ),
Fit Where( :Slot_id == 12, Fit Each Value( {Line Color( {210, 38, 158} )} ) ),
Fit Where( :Slot_id == 13, Fit Each Value( {Line Color( {141, 165, 48} )} ) ),
Fit Where( :Slot_id == 14, Fit Each Value( {Line Color( {106, 191, 140} )} ) ),
Fit Where( :Slot_id == 15, Fit Each Value( {Line Color( {23, 67, 132} )} ) ),
Fit Where( :Slot_id == 16, Fit Each Value( {Line Color( {144, 81, 160} )} ) ),
Fit Where( :Slot_id == 17, Fit Each Value( {Line Color( {220, 133, 105} )} ) ),
Fit Where( :Slot_id == 18, Fit Each Value( {Line Color( {97, 136, 48} )} ) ),
Fit Where( :Slot_id == 19, Fit Each Value( {Line Color( {41, 228, 161} )} ) ),
Fit Where( :Slot_id == 20, Fit Each Value( {Line Color( {155, 162, 199} )} ) ),
Fit Where( :Slot_id == 21, Fit Each Value( {Line Color( {109, 28, 105} )} ) ),
Fit Where( :Slot_id == 22, Fit Each Value( {Line Color( {160, 109, 62} )} ) ),
Fit Where( :Slot_id == 23, Fit Each Value( {Line Color( {127, 228, 79} )} ) ),
Fit Where( :Slot_id == 24, Fit Each Value( {Line Color( {53, 113, 105} )} ) ),
Fit Where( :Slot_id == 25, Fit Each Value( {Line Color( {55, 42, 208} )} ) ),
SendToReport(
Dispatch( {}, "1", ScaleBox, {Label Row( Show Major Grid( 1 ) )} ),
Dispatch( {}, "2", ScaleBox, {Minor Ticks( 1 ), Label Row( Show Major Grid( 1 ) )} ),
Dispatch( {}, "Bivar Plot", FrameBox, {Frame Size( 655, 344 ), Marker Size( 3 )} )
)
);<BR />
这会生成我需要的数据,但我不明白为什么下面的脚本没有。 它将为循环中的每个 slot_id 生成一个图,但没有“适合每个值”行和颜色分配
R = [213, 57, 64, 207, 33, 161, 200, 31, 201, 145, 35, 210, 141, 106, 23, 144, 220, 97, 41, 155, 109, 160, 127, 53, 55];
G = [72, 177, 111, 121, 189, 44, 193, 182, 37, 183, 157, 38, 165, 191, 67, 81, 133, 136, 228, 162, 28, 109, 228, 113, 42];
B = [87, 67, 223, 38, 145, 220, 39, 182, 205, 32, 195, 158, 48, 140, 132, 160, 105, 48, 161, 199, 105, 62, 79, 105, 208];
SlotNums = Associative Array( :slot_id );
UniqueSlots = slotnums << get keys;
For( i = 1, i <= N Items( uniqueslots ), i++,
If( i == 1,
lines = Eval(
"Fitwhere(:Slot_id == " || Char( uniqueslots[i] ) || ", " || "Fit Each Value( {Line Color( {" || Char( R[i] ) || ", " || Char( G[i] ) ||
", " || Char( B[i] ) || "} )} )),"
)
);
If( i < N Items( uniqueslots ),
Lines = Char( lines ) || Eval(
"Fitwhere(:Slot_id == " || Char( uniqueslots[i] ) || ", " || "Fit Each Value( {Line Color( {" || Char( R[i] ) || ", " || Char( G[i] ) ||
", " || Char( B[i] ) || "} )} )),"
)
);
If( i == N Items( uniqueslots ),
Lines = Char( lines ) || Eval(
"Fitwhere(:Slot_id == " || Char( uniqueslots[i] ) || ", " || "Fit Each Value( {Line Color( {" || Char( R[i] ) || ", " || Char( G[i] ) ||
", " || Char( B[i] ) || "} )} ))"
)
);
);
bivariate(
Y( :name( "1st Thickness PST" ) ),
X( :site ),
By( :Lot ),
Parse( lines ),
SendToReport(
Dispatch( {}, "1", ScaleBox, {Label Row( Show Major Grid( 1 ) )} ),
Dispatch( {}, "2", ScaleBox, {Minor Ticks( 1 ), Label Row( Show Major Grid( 1 ) )} ),
Dispatch( {}, "Bivar Plot", FrameBox, {Frame Size( 655, 344 ), Marker Size( 3 )} )
)
);
任何人都可以建议一种让它工作的方法吗?
我迟到了,但这是在较小的字符串上使用 Eval( Parse () ) 的另一种方法。这个可能更容易调试。如果您只想查看可视化,另一个选项可能是使用图形生成器(此脚本的底部)。
names default to here( 1 ) ;
//Sample data, add some categorical colums
dt = open( "$SAMPLE_DATA/football.jmp" );
dt << New Column( "Height Binned",
Numeric, "Ordinal", Format( "Best", 12 ),
Formula( Round( :Height * 2, -1 ) ) );
dt << New Column( "Weight Binned",
Numeric, "Ordinal", Format( "Best", 12 ),
Formula( Round( :Weight, -1 ) ) );
//colors
ColorList = {
[213, 72, 87], [57, 177, 67],
[64, 111, 223], [33, 121, 38]
};
Color = function( {n}, ColorList[ mod(n, n items( ColorList ) ) ] );
//base plot
bv = dt << Bivariate(
Y( :Speed ),
X( :Weight Binned ),
By( :Position2 ),
SendToReport(
Dispatch( {}, "1", ScaleBox, {Label Row( Show Major Grid( 1 ) )} ),
Dispatch( {}, "2", ScaleBox, {Minor Ticks( 1 ), Label Row( Show Major Grid( 1 ) )} ),
Dispatch( {}, "Bivar Plot", FrameBox, {Frame Size( 655, 344 ), Marker Size( 3 )} )
)
);
//get list of bins to fit, remove missing values
bincol = "Height Binned";
bins = (Associative Array( column(dt, bincol) ) << get keys);
//add each bin to the chart
if( ( N Items( bins ) > 0 ) ,
for( i = 1, i <= N Items( bins ), i++,
s = "bv << Fit Where( " ||
if( is missing( bins[i] ),
"is missing( :Name( \!"" || bincol || "\!" ) )",
":Name( \!"" || bincol || "\!" ) == " ||
char( bins[i] )
) ||
", Fit Each Value( Color( " || char( i ) || " ) ) )";
show(s);
Eval( Parse( s ) );
)
);
//Graph builder option
dt << Graph Builder(
Size( 425, 580 ),
Show Control Panel( 0 ),
Variables(
X( :Weight Binned ),
Y( :Speed ),
Group Y( :Position2 ),
Overlay( :Height Binned )
),
Elements( Line( X, Y, Legend( 17 ) ), Points( X, Y, Legend( 18 ) ) )
);
您的代码解析似乎没有连接“行”。以下解决方案将得到你想要的
R = [213, 57, 64, 207, 33, 161, 200, 31, 201, 145, 35, 210, 141, 106, 23, 144, 220, 97, 41, 155, 109, 160, 127, 53, 55];
G = [72, 177, 111, 121, 189, 44, 193, 182, 37, 183, 157, 38, 165, 191, 67, 81, 133, 136, 228, 162, 28, 109, 228, 113, 42];
B = [87, 67, 223, 38, 145, 220, 39, 182, 205, 32, 195, 158, 48, 140, 132, 160, 105, 48, 161, 199, 105, 62, 79, 105, 208];
SlotNums = Associative Array( :slot_id );
UniqueSlots = slotnums << get keys;
For( i = 1, i <= N Items( uniqueslots ), i++,
If( i == 1,
lines = Eval(
"Fitwhere(:Slot_id == " || Char( uniqueslots[i] ) || ", " || "Fit Each Value( {Line Color( {" || Char( R[i] ) ||
", " || Char( G[i] ) || ", " || Char( B[i] ) || "} )} )),"
)
);
If( i < N Items( uniqueslots ),
Lines = Char( lines ) || Eval(
"Fitwhere(:Slot_id == " || Char( uniqueslots[i] ) || ", " || "Fit Each Value( {Line Color( {" || Char( R[i] ) ||
", " || Char( G[i] ) || ", " || Char( B[i] ) || "} )} )),"
)
);
If( i == N Items( uniqueslots ),
Lines = Char( lines ) || Eval(
"Fitwhere(:Slot_id == " || Char( uniqueslots[i] ) || ", " || "Fit Each Value( {Line Color( {" || Char( R[i] ) ||
", " || Char( G[i] ) || ", " || Char( B[i] ) || "} )} ))"
)
);
);
Eval(
Parse(
"bivariate(
Y( :name( \!"1st Thickness PST\!" ) ),
X( :site ),
By( :Lot ),
" || lines ||
"),
SendToReport(
Dispatch( {}, \!"1\!", ScaleBox, {Label Row( Show Major Grid( 1 ) )} ),
Dispatch( {}, \!"2\!", ScaleBox, {Minor Ticks( 1 ), Label Row( Show Major Grid( 1 ) )} ),
Dispatch( {}, \!"Bivar Plot\!", FrameBox, {Frame Size( 655, 344 ), Marker Size( 3 )} )
)
);"
)
);