[JSL] add reference lines in graph builder with formula
This widget could not be displayed.
Created:
Feb 7, 2024 12:50 AM
| Last Modified: Feb 6, 2024 9:50 PM(1480 views)
Hi,
I am fairly new to JMP and I would like to be able to add variable references lines based on formula in the graph builder.
When I plot the Y with several X (groups), I would like to generate for each X in graph builder:
- 2 lines with the formula (Mean-4*Std ; Mean+4*Std)
- Fill the range with a color
- Label with the value on each line
I tried to add these lines in JSL but without success.
The following code works for a constant (200), and a simple variable (Column Mean (Y)) but I fail at adding more complexity (calculating the right value for each X group, fill the blank between the 2 lines, add label for the line)
I took a JMP data sample to show a quick example of my goal below (.PNG attached).
Thanks a lot for your help
Open( "$SAMPLE_DATA/Cholesterol Stacked.jmp" );
temp = Graph Builder(
Size( 715, 637 ),
Variables( Y( :Y ), Group X( :Treatment ) ),
Elements( Points( Y, Legend( 5 ) ) ),
SendToReport(
Dispatch(
{},
"Y",
ScaleBox,
{Min( -123.790318945935 ), Max( 574.600650636745 ), Inc( 100 ),
Minor Ticks( 1 )}
)
)
);
DataMean = 100; /* that code works with a constant*/
DataMean2 = Col Mean( :Y ); /* that code works with a simple variable */
report(temp)[axisbox(2)] << Add Ref Line( DataMean, "solid", red, "label1", 1 );
report(temp)[axisbox(2)] << Add Ref Line( DataMean2, "solid", red, "label2", 1 );
Re: [JSL] add reference lines in graph builder with formula
This widget could not be displayed.
Created:
Feb 7, 2024 02:17 AM
| Last Modified: Feb 6, 2024 11:44 PM(1471 views)
| Posted in reply to message from Voizingu 02-07-2024
To calculate mean for each of the groups, you can create new column to your table using Col Mean with ByVar, other option is to use Summarize function (or create summary table).
Generally I would first trying to build something like this by creating new columns and using multiple plot types overlaid. New columns for lines and adding line chart. Getting to this point is easy
Names Default To Here(1);
dt = Open("$SAMPLE_DATA/Cholesterol Stacked.jmp");
dt << New Column("NegLimit", Numeric, Continuous, Formula(
Col Mean(:Y, :Treatment) - 4 * Col Std Dev(:Y, :Treatment)
));
dt << New Column("PosLimit", Numeric, Continuous, Formula(
Col Mean(:Y, :Treatment) + 4 * Col Std Dev(:Y, :Treatment)
));
gb = dt << Graph Builder(
Size(673, 592),
Show Control Panel(0),
Variables(
Y(:Y),
Y(:NegLimit, Position(1)),
Y(:PosLimit, Position(1)),
Group X(:Treatment)
),
Elements(
Points(Y(1), Legend(5)),
Line(Y(2), Y(3), Legend(7), Fill("Fill Between"))
),
SendToReport(
Dispatch(
{},
"Y",
ScaleBox,
{Min(-123.790318945935), Max(574.600650636745), Inc(100), Minor Ticks(1)
}
)
)
);
Then you start working on labels and it can quickly get very messy (labelling definitely isn't strong part of graph builder).
These could of course be built using graphic scripts, but how that should be scripted is 100% dependent on your data and your visualization (there is usually quite a lot to take into account).
Edit:
One option on how far you can get with new columns, new rows and graph builder
Re: [JSL] add reference lines in graph builder with formula
This widget could not be displayed.
Created:
Feb 7, 2024 02:17 AM
| Last Modified: Feb 6, 2024 11:44 PM(1472 views)
| Posted in reply to message from Voizingu 02-07-2024
To calculate mean for each of the groups, you can create new column to your table using Col Mean with ByVar, other option is to use Summarize function (or create summary table).
Generally I would first trying to build something like this by creating new columns and using multiple plot types overlaid. New columns for lines and adding line chart. Getting to this point is easy
Names Default To Here(1);
dt = Open("$SAMPLE_DATA/Cholesterol Stacked.jmp");
dt << New Column("NegLimit", Numeric, Continuous, Formula(
Col Mean(:Y, :Treatment) - 4 * Col Std Dev(:Y, :Treatment)
));
dt << New Column("PosLimit", Numeric, Continuous, Formula(
Col Mean(:Y, :Treatment) + 4 * Col Std Dev(:Y, :Treatment)
));
gb = dt << Graph Builder(
Size(673, 592),
Show Control Panel(0),
Variables(
Y(:Y),
Y(:NegLimit, Position(1)),
Y(:PosLimit, Position(1)),
Group X(:Treatment)
),
Elements(
Points(Y(1), Legend(5)),
Line(Y(2), Y(3), Legend(7), Fill("Fill Between"))
),
SendToReport(
Dispatch(
{},
"Y",
ScaleBox,
{Min(-123.790318945935), Max(574.600650636745), Inc(100), Minor Ticks(1)
}
)
)
);
Then you start working on labels and it can quickly get very messy (labelling definitely isn't strong part of graph builder).
These could of course be built using graphic scripts, but how that should be scripted is 100% dependent on your data and your visualization (there is usually quite a lot to take into account).
Edit:
One option on how far you can get with new columns, new rows and graph builder