Chapter 11: Graph Components

Question 11.1:  How do I replace the default axis label with a different label in Graph Builder?

Question 11.2:  The font size, type, style, and color of the axis labels need to be changed in my report. How do I accomplish this?

Question 11.3: How do I specify a different font for the tick labels on my graph?

Question 11.4:  The tick labels on an axis need to be rotated and formatted to two decimal places. How is this done?

Question 11.5: How can I specify the order of values on an axis?

Question 11.6: How do I add a reference line on any graph?

Question 11.7:  How can I remove a reference line?

Question 11.8: How do I add annotations to my graph using a script?

Question 11.9:  I have a spec limits table with columns holding limits for each process variable. I want to plot these limits on Oneway plots. How can I do this?

Question 11.10: How can I get consistent legend colors when using a local data filter with Graph Builder?

 

 

Question 11.1:  How do I replace the default axis label with a different label in Graph Builder? 

Solution 11.1:

Updating axis labels in Graph Builder is a bit different from updating other graphs in JMP.  For Graph Builder, it is best to perform the actions interactively, and then capture the report customizations by saving the script.

After generating Graph Builder, delete the axis labels interactively and save the script. Notice that in the  SendToReport and Dispatch sections of the script, the current axis label text has been removed.

This code sample shows two options for changing the label for each axis, X and Y.  For Option 1, send messages to the appropriate AxisBoxes to add your custom labels.  For Option 2, simply replace the text in the Set Text() message with the desired label.

Option 1:

/* Open the Big Class sample data table */

dt = Open( "$SAMPLE_DATA/Big Class.jmp" );

 

/* Create the desired analysis and remove the default axis labels */

ov = dt << Graph Builder(

    Show Control Panel( 0 ),

    Variables( X( :height ), Y( :weight ) ),

    Elements( Points( X, Y, Legend( 1 ) ) ),

    SendToReport(

        Dispatch( {}, "X title", TextEditBox, {Set Text( "" )} ),

        Dispatch( {}, "Y title", TextEditBox, {Set Text( "" )} )

    )

);

 

/* Replace the X axis label */

Report( ov )[AxisBox( 1 )] << Add Axis Label( "Class Height" );

 

/* Replace the Y axis label */

Report( ov )[AxisBox( 2 )] << Add Axis Label( "Class Weight" );

Option 2:

/* Open the Big Class sample data table */

dt = Open( "$SAMPLE_DATA/Big Class.jmp" );

 

/* Create the desired analysis and remove the default axis labels */

ov = dt << Graph Builder(

    Show Control Panel( 0 ),

    Variables( X( :height ), Y( :weight ) ),

    Elements( Points( X, Y, Legend( 1 ) ) ),

    SendToReport(

        Dispatch( {}, "X title", TextEditBox, {Set Text( "Class Height" )} ),

        Dispatch( {}, "Y title", TextEditBox, {Set Text( "Class Weight" )} )

    )

);

Result 11.1:

Figure 11.1 Graph Builder Axis Labels Before

Figure 11.1 Graph Builder Axis Labels Before

Figure 11.2 Graph Builder Axis Labels After

Figure 11.2 Graph Builder Axis Labels After

Note: For most other platforms, you can change the axis label by sending the Remove Axis Label message to the AxisBox followed by the Add Axis Label() message to establish the desired axis label.  Here is one example to demonstrate:

biv = dt << Bivariate( Y( :weight ), X( :height ), Fit Line );

 

Report( biv )[AxisBox( 1 )] << Remove Axis Label;

Report( biv )[AxisBox( 1 )] << Add Axis Label( "Class Height" );

 

Report( biv )[AxisBox( 2 )] << Remove Axis Label;

Report( biv )[AxisBox( 2 )] << Add Axis Label( "Class Weight" );

 

Question 11.2:  The font size, type, style, and color of the axis labels need to be changed in my report. How do I accomplish this?  

Solution 11.2:

Send messages to the appropriate Text Edit Box, 1 for the Y axis and 2 for the X axis, to make the changes: Set Font Size, Set Font Style, and Font Color, as shown in the following code:

/* Open the Big Class sample data table */

dt = Open( "$SAMPLE_DATA/Big Class.jmp" );

 

/* Create the desired analysis */

ow = dt << Oneway(

    Y( :height ),

    X( :sex ),

    Means( 1 ),

    Box Plots( 1 ),

    Mean Diamonds( 1 )

);

 

/* Y axis label is Text Edit Box(1) in this example */

Report( ow )[Text Edit Box( 1 )] << Set Font Size( 14 )

    << Set Font( "Arial" )

    << Set Font Style( "Italic" )

    << Font Color( "Red" );

 

/* X axis label is Text Edit Box(2) in this example */

Report( ow )[Text Edit Box( 2 )] << Set Font Size( 14 )

    << Set Font( "Arial" )

    << Set Font Style( "Italic" )

    << Font Color( "Red" );

Result 11.2:

Figure 11.3 Oneway Axis Labels Before

Figure 11.3 Oneway Axis Labels Before

Figure 11.4 Oneway Axis Labels After

Figure 11.4 Oneway Axis Labels After

For information about JMP colors, see the Scripting Guide. To determine which fonts are available on your machine, right-click an axis, select the Axis Settings dialog window, and then click the Font button.

Figure 11.5 Font Settings

Figure 11.5 Font Settings

 

Question 11.3: How do I specify a different font for the tick labels on my graph?

Solution 11.3:

Use the Tick Font() message for the AxisBox, where you can specify font name, size, and style arguments, as shown in the following code:

/* Open the Big Class sample data table */

dt = Open( "$SAMPLE_DATA/Big Class.jmp" );

 

/* Create the desired analysis */

gb = dt << Graph Builder(

    Show Control Panel( 0 ),

    Variables( X( :height ), Y( :weight ), Overlay( :sex ) ),

    Elements( Points( X, Y, Legend( 1 ) ), Smoother( X, Y, Legend( 2 ) ) )

);

 

/* Create a report object */

repGB = gb << Report;

 

/* Set the style, size, and face using Tick Font */

repGB[AxisBox( 1 )] << Tick Font( "Arial", 12, "Bold Italic" );

repGB[AxisBox( 2 )] << Tick Font( "Arial", 12, "Bold Italic" );

To determine the fonts, font styles, and sizes that are available on a machine, right-click a plot axis, select the Axis Settings dialog window, and then click the Font button (see Figure 11.5).

 

Result 11.3:

Figure 11.6 Tick Font Changes

Figure 11.6 Tick Font Changes

 

Question 11.4:  The tick labels on an axis need to be rotated and formatted to two decimal places. How is this done?

 

Solution 11.4:

Rotating tick labels and specifying the format can be accomplished by sending the Axis Settings() message to the AxisBox.  Rotate the labels using the Label Orientation setting, and use the Format() message to change the formatting of the labels. Both messages are sent to the AxisBox, as shown in the following code:

/* Open the Big Class sample data table */

dt = Open( "$SAMPLE_DATA/Big Class.jmp" );

 

/* Create the desired analysis */

biv = dt << Bivariate( Y( :height ), X( :weight ) );

 

/* Set tick label format to vertical with 2 decimal places */

Report( biv )[AxisBox( 2 )] << Axis Settings(

    {Format( "Fixed Dec", 12, 2 ), LabelRow( Label Orientation( "Vertical" ) )}

);

The Axis Settings() message accepts a list argument containing named arguments that correspond to the settings available in the Axis Settings dialog.

Result 11.4:

Figure 11.7 Tick Orientation and Format Changes

Figure 11.7 Tick Orientation and Format Changes

To see the available options for the Format() function, right-click an axis, select the Axis Settings dialog window, and then click the down arrow for Format to display the list.  You can see the Label Orientation options in this dialog, as well.

Figure 11.8 Axis Setting Format Menu

Figure 11.7 Axis Setting Format Menu

 

Question 11.5: How can I specify the order of values on an axis?  

 

Solution 11.5:

Assign the Value Ordering column property using the Set Property() message for the column, as shown in the following code:

/* Open the Big Class sample data table */

dt = Open( "$SAMPLE_DATA/Big Class.jmp" );

 

/* Assign the Value Ordering column property */

Column( "age" ) << Set Property( "Value Ordering", {17, 15, 16, 12, 13, 14} );

 

/* Create a Bar Chart to see the effect */

gb = dt << Graph Builder(

    Size( 533, 448 ),

    Show Control Panel( 0 ),

    Variables( X( :age ), Y( :height ) ),

    Elements( Bar( X, Y, Legend( 6 ) ) )

);

Result 11.5:

To check the Value Ordering property for the column age, right-click the column heading, and then select Column Info.

Figure 11.9 New Value Ordering Property

Figure 11.9 New Value Ordering Property

Figure 11.10 Bar Chart Demonstrates the New Axis Order

Figure 11.10 Bar Chart Demonstrates the New Axis Order

Question 11.6: How do I add a reference line on any graph? 

Solution 11.6:

Send an Add Ref Line() message to the AxisBox,as shown in the following code:

/* Open the Big Class sample data table */

dt = Open( "$SAMPLE_DATA/Big Class.jmp" );

 

/* Create the desired analysis */

biv = dt << Bivariate( Y( :weight ), X( :height ) );

 

/* Add a reference line to the Y axis */

Report( biv )[Axisbox( 1 )] << Add Ref Line( 100, "Solid", "Red" ); 

/* Add a reference line to the X axis */

Report( biv )[Axisbox( 2 )] << Add Ref Line( 55, "Dashed", "Green" );

This example is for the Bivariate plot, but the concepts are the same for other graphs as well. The Add Ref Line message requires the number coordinate argument. Line style and color arguments might be included, as this example shows.

NOTE: For Graph Builder, it is best to perform the actions interactively, and then capture the report customizations with the SendToReport and Dispatch scripts.  

Result 11.6:

Figure 11.11 Added Reference Lines

Figure 11.11 Added Reference Lines

Question 11.7:  How can I remove a reference line?  

Solution 11.7:

 Use the Remove Ref Line() message with the location of the line as its argument, as shown in the following code:

/* Open the Big Class sample data table */

dt = Open( "$SAMPLE_DATA/Big Class.jmp" );

 

/* Create the desired analysis */

biv = dt << Bivariate( Y( :weight ), X( :height ) );

 

/* Add a reference line to the Y axis */

Report( biv )[Axisbox( 1 )] << Add Ref Line( 100, "Solid", "Red" );  

 

Wait( 2 );  /* Added for demonstration purposes only */

 

/* Remove the reference line. */

Report( biv )[AxisBox( 1 )] << Remove Ref Line( 100 );

 

Result 11.7:

Figure 11.12 Reference Line Before

Figure 11.12 Reference Line Before

Figure 11.13 Reference Line Removed

Figure 11.13 Reference Line Removed

 

Question 11.8: How do I add annotations to my graph using a script?

 

Solution 11.8:

Use the Text() function within Add Graphics Script(), as shown in the following code:

/* Open the Big Class sample data table. */

dt = Open( "$SAMPLE_Data/Big Class.jmp" );

 

/* Generate the desired graph. */

cc = dt << Control Chart(

    Sample Label( :age ),

    KSigma(3 ),

    Chart Col( :height, Individual Measurement )

);

 

/* Use the Text function within Add Graphics Script() to add the desired text to the graph. */

Report( cc )[Framebox( 1 )] << Add Graphics Script(

    Text( right justified, {30, 55.0}, "ABC" );

    Text( right justified, {30, 70.0}, "XYZ" );

);

The Add Graphics Script() message enables running a script within a graph.

The Scripting Guide and the Scripting Index, under “Functions,” provide information about the various options available for the Text() function, including color, font, position, and orientation. 

Result 11.8:

Figure 11.14 Control Chart with Text Annotations

Figure 11.14 Control Chart with Text Annotations

Question 11.9:  I have a spec limits table with columns holding limits for each process variable. I want to plot these limits on Oneway plots. How can I do this? 

 

Solution 11.9:

Use Add Ref Line() to add lines to the plot, and as the argument to the command, use column and row references to the specific cell containing that information in the spec limits table, as shown in the following code:

/* Open the sample data table, Big Class.jmp */

dt1 = Open( "$SAMPLE_DATA/Big Class.jmp" ); 

 

/* For demonstration purposes, create a table with spec limits */

dt2 = New Table( "Spec Limits Table",

    Add Rows( 2 ),

    New Column( "Process Column",

        Character, Nominal, Set Values( {"height", "weight"} ) ),

    New Column( "Lower Spec Limit",

        Numeric, Continuous, Format("Best", 10 ), Set Values( [60, 90] ) ),

    New Column( "Upper Spec Limit",

        Numeric, Continuous, Format("Best", 10 ), Set Values( [70, 150] ) )

);

 

/* Capture a list of variables to be used in Oneway analyses */

varList = dt1 << Get Column Names( "Continuous" );

 

/* Use a For loop to create a Oneway ANOVA for each member of the variable list */

For( i = 1, i <= N Items( varList ), i++,

    ow = dt1 << Oneway( Y( varList[i] ), X( :sex ),

        Means( 1 ), Box Plots( 0 ), Mean Diamonds( 1 )

    );

 

    /* Find the row in the data table that matches the column variable name */   

    rownum = dt2 << Get Rows Where( :Process Column == Char( varList[i] ) );

 

    /* Assign the limit value from adjacent columns on that row, using the rownum  

    variable value */   

    lower = Column( dt2, "Lower Spec Limit" )[rownum[1]];

    upper = Column( dt2, "Upper Spec Limit" )[rownum[1]];

 

    /* Add reference lines to the Oneway plot, based on the spec limit values

    assigned */

    Report( ow )[Axisbox( 1 )] << Add Ref Line( lower, "Solid", "Red" );

    Report( ow )[Axisbox( 1 )] << Add Ref Line( upper, "Solid", "Red" );

);

Result 11.9:

Figure 11.15 Oneway Plots with Limit Lines Added

Figure 11.15 Oneway Plots with Limit Lines Added   

 

Question 11.10: How can I get consistent legend colors when using a local data filter with Graph Builder?

 

Solution 11.10:

When filtering a graph using a local data filter, it is possible to filter down to a subset of rows such that only some of the levels appear in the graph.  When this occurs, the levels might be assigned different colors in the legend than when all the levels appeared.

To ensure that the items in the legend remain the same, create a new column called “Legend,” or named as appropriate for your data, with a Value Colors column property.  Assign categories to your grouping variable combinations in the Legend column.  When creating your Graph Builder plot, cast the Legend column into the Overlay role:

/* Open the sample data table, Wine Sensory Data.jmp */

dt = Open( "$SAMPLE_DATA/Wine Sensory Data.jmp" );

 

/* Add a column to summarize data */

dt << New Column( "Summary Rating",

    Numeric,

    "Continuous",

    Format( "Best", 12 ),

    Formula(

      Sum( :Carolyn Tannic + :Carolyn Peppery + :Carolyn Aromatic + :Carolyn Berry Notes ))

);

 

/* Add a column to create categories for the legend */

dt << New Column( "Legend",

    Character,

    "Nominal",

    Formula(

            If(

                    :Summary Rating < 17.5, "Low",

                    17.5 <= :Summary Rating <= 21.5, "Good",

                    21.5 < :Summary Rating <= 26, "Better",

                    :Summary Rating > 26, "Best",

                    "Unknown"

            )

    ),

    Set Property( "Value Colors",

            {"Best" = "Purple", "Better" = "Blue", "Good" = "Green", "Low" = "Red"} )

);

 

/* Create a list of all unique wine regions for the grouping variable */

/* The Summarize() function can be used as an alternative */

RegionList = Associative Array( :Region ) << Get Keys;

 

/* Create new window, which will show a report for each region, for demonstration purposes */

nw = New Window( "Legend Category Color Variation" );

 

/* Loop through each wine region and append Graph Builder to the window */

For( i = 1, i <= N Items( RegionList ), i++,

    nw << Append(

        Outline Box( RegionList[i],

            gb = dt << Graph Builder(

                Size( 528, 477 ),

                Show Control Panel( 0 ),

                Variables( X( :Vineyard ), Y( :Summary Rating ), Overlay( :Legend ) ),

                Elements( Bar( X, Y, Legend( 6 ), Summary Statistic( "Sum" ) ) ),

                Local Data Filter(

                    Add Filter( columns( :Region ), Where( :Region == RegionList[i]) ) ) )

        )

    )

);

This example uses the sample data table, Wine Sensory Data.jmp.  Carolyn’s wine sensory data columns are summed in the new column, Summary Rating.  Another new column named Legend is created, where legend values are assigned into one of four categories based on the values from Summary Rating.

Result 11.10:

The data table with added columns is shown first, followed by the reports with the local data filters.

Figure 11.16 Wine Sensory Data Table with Added Columns

Figure 11.16 Wine Sensory Data Table with Added Columns

Figure 11.17 Graph Builder Bar Charts with Local Data Filters (Excerpt)

Figure 11.17 Graph Builder Bar Charts with Local Data Filters (Excerpt)

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset