泰勒图生成器表达式亲爱的社区:
我想制作一个图形生成器脚本(想将其作为脚本放在新表中),其中包含一长串 y 变量。
我的第一个方法是尝试表达式操作,但这并没有像预期的那样有效。
有人能解释一下编写该脚本的最佳方法是什么吗?
下面的示例也包含我当前的方式,创建 GB 实例,然后添加 y 变量。
谢谢,并致以最诚挚的问候,
Names Default To Here( 1 );
cdt = Open( "$SAMPLE_DATA\Big Class.jmp" );
col_lst = cdt << get column names( Continuous, "String" );
gb_expr = Expr(
cdt << Graph Builder(
Size( 534, 450 ),
Show Control Panel( 0 ),
Variables( X( :age ), Y( :height ) ),
Elements( Position( 1, 1 ), Points( X, Y, Legend( 4 ) ) ),
Elements( Position( 1, 2 ), Points( X, Y, Legend( 5 ) ) )
)
);
// this does not work, Expr() does not accept comma separated items
// Substitute Into( gb_expr, Expr( Y( :height ) ), Expr( Y( :height ), Y( :weight ) ) );
// gb_obj = gb_expr;
// this works
// creating GB instance
gb_obj = cdt << Graph Builder(
Size( 534, 450 ),
Show Control Panel( 0 ),
Variables( X( :age )),
Elements( Position( 1, 1 ), Points( X, Y, Legend( 4 ) ) ),
Elements( Position( 1, 2 ), Points( X, Y, Legend( 5 ) ) )
);
// adding Y's
For Each( {ycol}, col_lst, Eval( Parse( Eval Insert( "gb_obj << variables( Y(:^ycol^ ))" ) ) ) );
// this I would like to create directly, w/o large parse/eval parts, that are bad for maintenance
my_target_expression = gb_obj << get script();
自动化和脚本回复:泰勒图生成器表达式这项使用 Eval(Eval Expr()) 的微小更改可能会为您提供所需的功能
Names Default To Here( 1 );
cdt = Open( "$SAMPLE_DATA\Big Class.jmp" );
col_lst = cdt << get column names( Continuous, "String" );
gb_expr = Expr(
cdt << Graph Builder(
Size( 534, 450 ),
Show Control Panel( 0 ),
Variables( X( :age ), Y( :height ) ),
Elements( Position( 1, 1 ), Points( X, Y, Legend( 4 ) ) ),
Elements( Position( 1, 2 ), Points( X, Y, Legend( 5 ) ) )
)
);
// this does not work, Expr() does not accept comma separated items
// Substitute Into( gb_expr, Expr( Y( :height ) ), Expr( Y( :height ), Y( :weight ) ) );
// gb_obj = gb_expr;
// this works
// creating GB instance
gb_obj = cdt << Graph Builder(
Size( 534, 450 ),
Show Control Panel( 0 ),
Variables( X( :age ) ),
Elements( Position( 1, 1 ), Points( X, Y, Legend( 4 ) ) ),
Elements( Position( 1, 2 ), Points( X, Y, Legend( 5 ) ) )
);
// adding Y's
For Each( {ycol}, col_lst,
Eval( Eval Expr( gb_obj << variables( Y( Expr( ycol ) ) ) ) )
);
// this I would like to create directly, w/o large parse/eval parts, that are bad for maintenance
my_target_expression = gb_obj << get script();回复:泰勒图生成器表达式嗨吉姆,
谢谢,使用 eval/evalexpr 也同样有效。
但我的问题是,我怎样才能在上面部分构建完整的 gb_expr,
我的亮点是:
Substitute Into( gb_expr, Expr( Y( :height ) ), Expr( Y( :height ), Y( :weight ) ) );
不工作。
因此我想使用表达式操作(而不是字符串操作)将许多“Y(:c1),Y(:c2)...”替换到 Graph Builder 表达式中。
此致,
回复:泰勒图生成器表达式我不知道如何解决替代问题。您可能想探索可以传递给 Graph Builder 的脚本索引 Graph Builder 消息

Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
gb = Graph Builder(
Variables( X( :sex ) ),
Elements( Points( X, Y ), Smoother( X, Y ) )
);
gb << Add Variable( {:height, Role( "Y" )} );
gb << Add Variable( {:weight, Role( "Y" )} );回复:泰勒图生成器表达式@Georg
根据@txnelson关于向图形生成器发送消息的建议,这可能会让你更接近你正在寻找的内容:
Names Default To Here( 1 );
cdt = Open( "$SAMPLE_DATA/Big Class.jmp" );
col_lst = cdt << get column names( Continuous, "String" );
gb = Graph Builder(
Variables( X( :age ) ),
Elements( Points( X, Y ) )
);
for each( { yCol }, col_lst,
gb << Add Variable( { eval( yCol ), Role( "Y" ) } );
);
生成的图形生成器脚本是:
Graph Builder(<BR />Variables( X( :age ), Y( :height ), Y( :weight ) ),<BR />Elements( Position( 1, 1 ), Points( X, Y, Legend( 1 ) ) ),<BR />Elements( Position( 1, 2 ), Points( X, Y, Legend( 2 ) ) )<BR />);
回复:泰勒图生成器表达式感谢大家,看起来不错!
回复:泰勒图生成器表达式我通常不使用替代品,而是使用表达式来构建它们,下面是一个选项,但还有其他选项
Names Default To Here(1);
dt = Open("$SAMPLE_DATA\Big Class.jmp");
col_lst = cdt << get column names(Continuous, "String");
var_expr = Expr(Variables(X(:age)));
For Each({colname}, col_lst,
colname = "height";
Insert Into(var_expr, EvalExpr(Y(Expr(Name Expr(As Column(dt, colname))))));
);
gb_expr = EvalExpr(
dt << Graph Builder(
Size(534, 450),
Show Control Panel(0),
Expr(Name Expr(var_expr))
);
);
gb = Eval(gb_expr);
// gb << get script
gb << Save Script to Data Table("Plot");
如果您只是想使用替代,我认为您必须替换整个变量部分(或者可能做一些技巧)
Names Default To Here(1);
cdt = Open("$SAMPLE_DATA\Big Class.jmp");
col_lst = cdt << get column names(Continuous, "String");
gb_expr = Expr(
cdt << Graph Builder(
Size(534, 450),
Show Control Panel(0),
Variables(X(:age), Y(:height)),
Elements(Position(1, 1), Points(X, Y, Legend(4))),
Elements(Position(1, 2), Points(X, Y, Legend(5)))
)
);
Substitute Into(gb_expr, Expr(Variables(X(:age), Y(:height))), Expr(Variables(X(:age), Y(:height), Y(:weight))));
show(gb_expr);