cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • We’re improving the Learn JMP page, and want your feedback! Take the survey
  • JMP monthly Newswire gives user tips and learning events. Subscribe
Choose Language Hide Translation Bar
seanschubert
Level I

custom graph legend

I'm trying to add a nice pretty graph legend to a Bivariate Fit:

 

seanschubert_3-1749609654606.png

 

The orange fit line is a customized line added using this script:

    Pen Color( "orange" );
    Pen Size( 2 );
    Y Function( 21.07 * x, x );

 

I used this custom script in the graph to get that text in there:
    Text( {20, 32}, "TOT Other = 21.1 * 3XL" );
    Text( {20, 25}, "TOT Other = 46.8 + 9.1*3XL" );
    Text( {20, 19}, "Log(TOT Other) = 3.0 + 0.75*Log(3XL)" );

 

I'd like to put those equations into a nice legend box and color each text by its color in the graph and maybe make the text bold.

 

Any ideas on how to do it in the script or adding the orange fit as another model to the fits below?

 

- Sean

 

2 REPLIES 2
jthi
Super User

Re: custom graph legend

You can use change the text color by using Text Color() before text, for the border one option is to use Rect

Names Default To Here(1);
New Window("Example",
	Graph Box(
		Text Color("green");
		Text(Center Justified, {50, 15}, "centered");
		Text Color("blue");
		Text(Center Justified, {50, 20}, "centered");
		Text Color("red");
		Text(Center Justified, {50, 25}, "centered");
		Pen Color("Black");
		Rect(40, 30, 60, 14);
	)
);

jthi_0-1749615113563.png

I'm not sure if Fit Y by X lets you add custom fits but you could take a look at properties to see how those have been built

jthi_1-1749615299817.png

and try to imitate that

 

Names Default To Here(1);
dt = Open("$SAMPLE_DATA/Big Class.jmp");
obj = dt << Bivariate(Y(:Weight), X(:Height));
obj << Fit Line;

Report(obj)[ListBox(4)] << Append(
	H List Box(align("center"),
		Popup Box({"",1 }),
		//Spacer Box(Size(15, 0)), // to leave empty instead of red triangle
		Spacer Box(Size(22, 2), Color("Orange")),
		Text Box(" myfit")
	)
);

jthi_2-1749615580137.png

 

-Jarmo

Re: custom graph legend

For the greatest flexibility and customization, I believe Graph Builder is better suited than Fit Y by X.

Once you have the information you need from the Bivariate platform, could you save the fit equations as columns (red triangle -> save predicteds)? If you name each of these new fit columns with the expression for that equation, then that text will show up by default in legends. 

To replicate your plot in Graph Builder, add the data plus all the fits in the Y-role, and "3XL" in the X-role. For the plot types, use Points for the data, and Function for the fits. Legend text can be made bold from the Legend Settings. An outline box can be added by right clicking in the legend (not on the text), and selecting Show Properties, then set Border=1 for all four sides. Click and drag the legend to place it anywhere in the window. These customizations can all be saved to the table, to a workflow, or to a script window. 

I'm not aware of a way to set the legend text color to match the plot color automatically, unfortunately. 

Recommended Articles