Subscribe Bookmark RSS Feed

How to globally set levels in a chart

mdawson69

Community Trekker

Joined:

Aug 26, 2015

I have a few scripts that I use that were created from charts. Often these charts have data that JMP separates into levels although for my purposes, they are effectively the same. For example the following code is for a chart of mean exclusion rates across sites.

Chart(

    X(:IDENT Code),

    Y(Mean(:Exclusion Rate)),

    Add Error Bars to Mean(Name("Confidence Interval (pooled)")(0.95)),

    Overlay Axis << {{Format("Fixed Dec", 12, 3), Min(0.935), Max(0.9975),

    Inc(0.005), Minor Ticks(1)}},

    Overlay Stack Axis << {{Format("Fixed Dec", 12, 0), Min(-1.5), Max(8.5), Inc(1),

    Minor Ticks(1)}},

    Level[1] << {Colors(-4221340), Markers(29)},

    Level[2] << {Colors(-4221340), Markers(29)},

    Level[3] << {Colors(-4221340), Markers(29)},

    Level[4] << {Colors(-4221340), Markers(29)},

    Level[5] << {Colors(-4221340), Markers(29)},

    Level[6] << {Colors(-4221340), Markers(29)},

    Level[7] << {Colors(-4221340), Markers(29)},

    Y[1] << Point Chart(1),

    SendToReport(

        Dispatch({}, "102", ScaleBox, {Format("Percent", 6, 0), Show Major Grid(1)}),

        Dispatch({}, "", AxisBox(2), {Add Axis Label("Mean(Exclusion Rate)")}),

        Dispatch({}, "Mean(Exclusion Rate)", TextEditBox, {Set Font Size(20)}),

        Dispatch(

            {},

            "Chart Graph",

            FrameBox,

            {Frame Size(704, 536), Marker Size(6)}

        )

    )

)


When the script was created for the previous report, there were seven sites, but now there are ten, so the last three plots use default settings. Is there a way to set these levels globally instead of individually for times like this when the number of levels have changed?

5 REPLIES
txnelson

Super User

Joined:

Jun 22, 2012

You can set the defaults in the Preferences:

File==>Preferences==>Graphs

The Default Marker and color set can be specified there

12506_pastedImage_0.png

If This does not do what you want, then your script could be easily modified to test for the number of levels found, and to generate the code as required.

Jim
mdawson69

Community Trekker

Joined:

Aug 26, 2015

Thanks, but that is not what I mean by globally. I am not interested in locking JMP into creating all charts the same way. I have scripts for specific data sets in an ongoing project where the number of levels may change from reporting period to reporting period. The way that JMP generates the script, the settings for levels are explicit, so I want to know if there is a way to set levels globally within a chart. I have a similar script for a data set with 46 levels and the script generated 46 Level parameter lines despite each level having the exact same settings.

It seems that JMP assumes that levels are always explicit and that the user always wants them represented differently in the graph. There are cases were that is true, but what is being deemed levels in this chart are the categories on the x-axis.

pmroz

Super User

Joined:

Jun 23, 2011

You can put a loop right in the chart code.

dt = New Table( "Example", Add Rows( 8 ),

    New Column( "IDENT Code", Character, "Nominal",

        Set Values( {"AA", "AA", "AA", "BB", "BB", "CC", "CC", "CC"} ) ),

    New Column( "Exclusion Rate", Numeric, "Continuous", Format( "Best", 12 ),

        Set Values( [0.05, 0.07, 0.08, 0.5, 0.6, 0.4, 0.3, 0.2] ) )

);

ident_codes  = dt:IDENT Code << get values;

unique_codes = get_unique_values(ident_codes);

ncodes       = nitems(unique_codes);

dt << Chart(

    X(:IDENT Code),

    Y(Mean(:Exclusion Rate)),

    Add Error Bars to Mean(Name("Confidence Interval (pooled)")(0.95)),

    Overlay Axis << {{Format("Fixed Dec", 12, 3), Min(0.935), Max(0.9975),

    Inc(0.005), Minor Ticks(1)}},

    Overlay Stack Axis << {{Format("Fixed Dec", 12, 0), Min(-1.5), Max(8.5), Inc(1),

    Minor Ticks(1)}},

// Assign each level the same color and marker

    for (i = 1, i <= ncodes, i++,

        level[i] << {Colors(-4221340), Markers(29)},

    ),

    Y[1] << Point Chart(1),

    SendToReport(

        Dispatch({}, "102", ScaleBox, {Format("Percent", 6, 0), Show Major Grid(1)}),

        Dispatch({}, "", AxisBox(2), {Add Axis Label("Mean(Exclusion Rate)")}),

        Dispatch({}, "Mean(Exclusion Rate)", TextEditBox, {Set Font Size(20)}),

        Dispatch(

            {},

            "Chart Graph",

            FrameBox,

            {Frame Size(704, 536), Marker Size(6)}

        )

    )

)

Here's the code for the get_unique_values function:

Get_unique_values = Function( {in_list},

      {Default Local},

      tmp = [=> 0];

      Insert Into( tmp, in_list );

      tmp << get keys;

);

mdawson69

Community Trekker

Joined:

Aug 26, 2015

This looks like it may be what I am looking for. I was wondering if I could put a For loop within chart code, but I was unaware that I could create user-defined functions in JSL or would have needed to in this case. I will try your solution out.

mdawson69

Community Trekker

Joined:

Aug 26, 2015

So, I am now i another reporting cycle and found this thread from last year. I tried pmroz’s suggestion yesterday and it worked great until it ceased doing so. The first time I used the technique presented by pmroz it worked perfectly. For each level in the data set, the correct color and marker type was applied to each point on the graph. When I attempted to use the technique in another data table script, it failed to work; the script executed without any errors being generated, but the default colors and marker for JMP were used instead of what I defined in the script. Interestingly, now the first script I modiifed also uses the JMP defaults instead of what I define in script.

 

Here is the code:

Names Default To Here(1);
Delete Symbols();

dt = Current Data Table();

UniqueValueList = Function({inList},
	{Default Local},
	tmp = [=> 0];
	Insert Into(tmp, inList);
	tmp << Get Keys;
);

identCodes = :IDENT Code << Get Values;
uniqueCodes = UniqueValueList(identCodes);
nCrossings = NItems(uniqueCodes);

dt << Chart(
	X(:IDENT Code),
	Y(Mean(:Read Rate)),
	Add Error Bars to Mean(Name("Confidence Interval (pooled)")(0.95)),
	Overlay Axis << {{Format("Fixed Dec", 12, 2), Min(0.77), Max(1.05), Inc(0.02),
	Minor Ticks(1)}},
	Overlay Stack Axis << {{Min(-10)}},
	For(i = 1, i <= nCrossings, i++,
		Level[i] << {Colors(-4221340), Markers(29)}
	),
	Y[1] << Point Chart(1),
	SendToReport(
		Dispatch(
			{},
			"102",
			ScaleBox,
			{Format("Percent", 6, 0), Minor Ticks(1), Show Major Grid(1),
			Show Minor Grid(0)}
		),
		Dispatch({}, "", AxisBox(2), {Add Axis Label("Mean(Read Rate)")}),
		Dispatch({}, "Mean(Read Rate)", TextEditBox, {Set Font Size(20)}),
		Dispatch(
			{},
			"Chart Graph",
			FrameBox,
			{Frame Size(1056, 464), Marker Size(6)}
		)
	)
)

Based on what I could see from the JSL debugger, nCrossings is being correctly set, but it seems like the For loop in the Chart statement is being ignored. Unfortunately, stepping through the code does not help as Chart is a single statement, so the debugger does not step through its code.

 

What am I doing wrong?