Estoy tratando de recrear el siguiente script usando un bucle (este script funciona, pero me gustaría que se ejecute como un bucle para que trate cada conjunto de datos de la misma manera):
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 />
Esto genera los datos que necesito, pero no entiendo por qué la secuencia de comandos a continuación no lo hace. Generará una gráfica pero sin las líneas de "ajuste a cada valor" y las asignaciones de color para cada slot_id en el bucle
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 )} )
)
);
¿Alguien puede sugerir un método para que esto funcione?
Llego tarde a la fiesta, pero aquí hay otra manera de usar Eval (Parse ()) en cadenas más pequeñas. Esta podría Ser más fácil de depurar. Si solo desea ver la visualización, otra opción podría ser utilizar el generador de gráficos (parte inferior de este script).
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 ) ) )
);
Parece que el análisis de su código no está conectando las "Líneas". La siguiente solución obtendrá lo que quieres
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 )} )
)
);"
)
);