我是 JMP 新手,在匯出多個箱形圖時遇到問題。我的目標是建立 X 軸變數按另一個參數分組的繪圖。但是,導出的輸出缺少一些 X 軸數據,即使當我使用單個特定列時繪圖是正確的。
這是我的程式碼:
//桌面創建資料夾帶上當天日期
timestamp = Format Date(Today(), "ddmmyyyy");
desktop_path = Get Environment Variable("USErProfile") || "$DESKTOP";
folder_path = desktop_path || "/JMP_Analysis_" || timestamp ;
CreateDirectory(folder_path);
// Set the output directory to the newly created folder
outputDir = folder_path || "/";
dt = Open(
"$DESKTOP/file/file.xls",
Worksheets( "Sheet1" ),
Use for all sheets( 1 ),
Concatenate Worksheets( 0 ),
Create Concatenation Column( 0 ),
Worksheet Settings(
1,
Has Column Headers( 1 ),
Number of Rows in Headers( 1 ),
Headers Start on Row( 1 ),
Data Starts on Row( 2 ),
Data Starts on Column( 1 ),
Data Ends on Row( 0 ),
Data Ends on Column( 0 ),
Replicated Spanned Rows( 1 ),
Replicated Spanned Headers( 0 ),
Suppress Hidden Rows( 1 ),
Suppress Hidden Columns( 1 ),
Suppress Empty Columns( 1 ),
Treat as Hierarchy( 0 ),
Multiple Series Stack( 0 ),
Import Cell Colors( 0 ),
Limit Column Detect( 0 ),
Column Separator String( "-" )
)
);
//將導入EXCEL之JMP存檔
dt << Save(outputDir || "Joe_CrazyFileCR.jmp");
// Identify rows corresponding to "Upper Limit" and "Lower Limit"
upperRow = dt << Get Rows Where(:Site == "Upper Limit");
lowerRow = dt << Get Rows Where(:Site == "Lower Limit");
// Ensure valid row indices for limits
If(N Rows(upperRow) == 0 | N Rows(lowerRow) == 0,
Throw("Error: Missing 'Upper Limit' or 'Lower Limit' row in the data.")
);
// Get the first row indices for upper and lower limits
upperRowIndex = upperRow[1];
lowerRowIndex = lowerRow[1];
// Loop through each column
For( i = 4, i <= N Cols( dt ), i++,
// Get column reference and name
col = Column( dt, i );
colName = col << Get Name;
// Retrieve the limit values for the current column
upperLimit = Num(dt[upperRowIndex, i]);
lowerLimit = Num(dt[lowerRowIndex, i]);
// Create a box plot for the column
bp = dt << Graph Builder(
Show Control Panel( 0 ),
Show Legend( 0 ),
Variables(
X( :Vendor1 ),
Y(col), // Box plot for the current column
Group X( :Vendor2 )
),
Elements( Box Plot( Y, Legend( 0 ) ) ),
// Add Reference Lines for Limits
SendToReport(
Dispatch(
{},
colName, // Use the column name to target the Y-axis scale,
ScaleBox,
{Add Ref Line(upperLimit, "Dashed", "Green", "Upper Limit"),
Add Ref Line(lowerLimit, "Dashed", "Red", "Lower Limit")}
)
)
);
// Save the plot as a JPEG file
bp << savepicture( outputDir || colName || ".jpeg", "JPEG" );
// Close the plot window without saving
);
Close All( data tables, No Save );這是缺少數據的圖片:

當我直接透過 UI 繪製時沒有問題:

我最初的猜測是,您的圖形生成器在腳本中構建不正確(確保將您的腳本與手動創建圖形獲得的腳本進行比較)。箱線圖的元素部分很可能不正確
bp = dt << Graph Builder(
Show Control Panel(0),
Show Legend(0),
Variables(
X(:Vendor1),
Y(Eval(col)), // Box plot for the current column
Group X(:Vendor2)
),
Elements(Box Plot(X, Y, Legend(1))),
// Add Reference Lines for Limits
SendToReport(
Dispatch({}, colName, // Use the column name to target the Y-axis scale,
ScaleBox,
{Add Ref Line(upperLimit, "Dashed", "Green", "Upper Limit"),
Add Ref Line(lowerLimit, "Dashed", "Red", "Lower Limit")}
)
)
);
另外,我會考慮以這樣的方式修改您的數據,即刪除規範限制行,因為這並不是您真正想要的數據方式。您可以將它們儲存到變數中,將它們設定為列屬性,或將它們儲存到表格變數中。
您的元素規格需要選擇 X 變數以及 Y 變數。您的代碼沒有經過檢查

將元素規範更改為
Elements( Box Plot( X, Y, Legend( 1 ) ) )
是的,這就是問題......哈哈!感謝您的幫助,下次將檢查所有細節...
我已確認參考圖中未包含極限值。我仍在嘗試理解原因,並將檢查更多結果。目前,我知道的唯一方法是將極限值與新的數據表分開,並用額外的循環代碼引用極限數據表,這對我來說很複雜。