使用主題格式的表達式我正在嘗試將多個相似圖的格式設定為一個表達式,以便我可以更改程式碼的單個部分來更新所有看起來相似的圖表。但是,我很難將其實現為程式碼。我包括一個最小的工作範例,顯示我希望繪圖是什麼樣子以及我希望我的程式碼是什麼樣子,儲存一段用於格式化的程式碼和每個繪圖的緊湊程式碼。關於如何修改它以使其工作有什麼想法嗎?我正在開發 JMP 版本 15.2。
dt = New Table( "Minimal Working Example",
Add Rows( 400 ),
New Column( "X", Numeric, Set Values( Repeat( 1 :: 20, 20 ) ) ),
New Column( "Y", Numeric, Set Values( Sort Ascending( Shape( Repeat( 1 :: 20, 20 ), 1 ) ) ) ),
New Column( "Size", Numeric, <<FORMULA></FORMULA>
<LINGO-LABS id="lingo-labs-398923" slang="en-US" mode="UPDATE"><LINGO-LABEL>進階統計建模</LINGO-LABEL><LINGO-LABEL>資料存取</LINGO-LABEL><LINGO-LABEL>資料混合與清理</LINGO-LABEL><LINGO-LABEL>大規模客製化</LINGO-LABEL></LINGO-LABS>回复:使用主題格式的表達式你好,
表達式處理功能強大,需要一些練習。 這是一個讓您入門的示例,但您需要閱讀 Eval()、Expr()、NameExpr()、Substitute()、Substitute Into() 等內容。
Names Default To Here(1);
//make a 5-column table
dt = astable((1::20)` || J(20,4,randominteger(0,20)));
//the x column will be the first column
xCol = column (dt, 1);
//the y columns will be the remaining columns
yColList = (dt << get column names())[2::ncol(dt)];
//write the graph builder script, wrapping it in an expression. Use _XXX_ format for things
//you'll be substituting later. Here, that is just the "y" variable for a particular graph.
gbExpr = expr(
dt << Graph Builder(
Variables( X( xcol ), Y( _Y_ ) ),
Elements( Points( X, Y, Legend( 8 ) ) ),
SendToReport(
Dispatch(
{},
"400",
ScaleBox,
{Legend Model(
8,
Properties(
0,
{gradient( {Color Theme( "White to Red" )} )},
Item ID( "Size", 1 )
)
)}
),
Dispatch(
{},
"400",
LegendBox,
{Legend Position( {8, [0, -1]} ), Legend Position( {0, -1} )}
)
)
);
);
//cycling through the items in yColList, we create a graph for each y variable vs the x variable.
//be sure to read up on Name Expr ( ), as it is needed here to prevent evaluation of the Graph
//Builder script... we just want the code itself... we don't want JMP to try to evaluate the code
//until after we've made the substitution.
for (i = 1,i <=nitems(ycolList), i++,
eval(Substitute( nameExpr(gbExpr), expr(_Y_) , expr(yColList[i])));
);
乾杯,
布雷迪
回覆:使用主題格式的表達式由於 X、Y 和 Color 變數在我的資料上發生變化的方式,這種方法效果不太好,但我設法使用 JSL Quote、Eval Insert、Parse 和 Eval 找到了更接近我想要的解決方案:
// A theme format I could change for a gazillion of plots
formats = JSL Quote(
SendToReport(
Dispatch(
{},
"400",
ScaleBox,
{Legend Model(
8,
Properties(
0,
{gradient( {Color Theme( "White to Red" )} )},
Item ID( "Size", 1 )
)
)}
),
Dispatch(
{},
"400",
LegendBox,
{Legend Position( {8, [0, -1]} ), Position( {0, -1} )}
)
)
);
// How I would like each plot code to look like
Eval(Parse(Eval Insert("dt << Graph Builder(
Variables( X( :X ), Y( :Y ), Color( :Size ) ),
Elements( Points( X, Y, Legend( 8 ) ) ),
^formats^
);")));