cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Check out the JMP® Marketplace featured Capability Explorer add-in
Choose Language Hide Translation Bar
MarkWu
Level I

Data missing when export multiple box plots with script.

I am new to JMP and encountering issues exporting multiple box plots. My goal is to create plots with X-axis variables grouped by another parameter. However, the exported output is missing some X-axis data, even though the plots are correct when I use a single specific column.

Here is my code:

//桌面創建資料夾帶上當天日期
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 );

And this is the picture with missing data:

MarkWu_0-1733883517938.png

And no issue when I drew by the UI directly:

MarkWu_1-1733883619712.png

 

2 ACCEPTED SOLUTIONS

Accepted Solutions
jthi
Super User

Re: Data missing when export multiple box plots with script.

My initial guess is that your graph builder is being built incorrectly in your script (make sure you compare your script to the one you get by manually creating the graph). The Elements part is most likely incorrect for Box Plot

	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")}
			)
		)
	);

Also I would consider modifying your data in such a way, that you remove specification limit rows as that isn't really how you would like to have your data. You can store them into a variable, set them as column properties or maybe store them to table variables.

-Jarmo

View solution in original post

txnelson
Super User

Re: Data missing when export multiple box plots with script.

Your Elements specification needs to have the X variable selected as well as the Y variable.  Your code does not have it checked

txnelson_1-1733937993262.png

Change the Elements specification to

Elements( Box Plot( X, Y, Legend( 1 ) ) )

 

Jim

View solution in original post

5 REPLIES 5
jthi
Super User

Re: Data missing when export multiple box plots with script.

Can you provide example of your data (.jmp file)?

-Jarmo
MarkWu
Level I

Re: Data missing when export multiple box plots with script.

Thanks for reply! Providing jmp in the attachment.

jthi
Super User

Re: Data missing when export multiple box plots with script.

My initial guess is that your graph builder is being built incorrectly in your script (make sure you compare your script to the one you get by manually creating the graph). The Elements part is most likely incorrect for Box Plot

	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")}
			)
		)
	);

Also I would consider modifying your data in such a way, that you remove specification limit rows as that isn't really how you would like to have your data. You can store them into a variable, set them as column properties or maybe store them to table variables.

-Jarmo
MarkWu
Level I

Re: Data missing when export multiple box plots with script.

Yes, That is the issue...lol! Thanks for help and will examine all the details next time...

I've confirmed that limit values aren't included in the reference drawings. I'm still try to understand why, and I'll examine more results. Currently, the only way I know is to separate limit values with a new data table and refer to the limit data table with additional loop code, which is complicated for me.

txnelson
Super User

Re: Data missing when export multiple box plots with script.

Your Elements specification needs to have the X variable selected as well as the Y variable.  Your code does not have it checked

txnelson_1-1733937993262.png

Change the Elements specification to

Elements( Box Plot( X, Y, Legend( 1 ) ) )

 

Jim