cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Choose Language Hide Translation Bar
Kenobi
Level III

Auto exclude a certain item from the legend

Hello,

 

I am trying to create a GraphBuilder plot, with a "Flag" column being used in the "Color" section as show below

 

Kenobi_0-1690487017131.png

I want my script to autoexclude a particular category, lets say "PASS" in this case. I am not sure on how to do that. Any suggestions would be very helpful

Kenobi_1-1690487054143.png

Thank you.

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

	y_name = Char(y_cols[i]);
	x_name = Char(x_col[1]);

	gb = dt << Graph Builder(
		Size(700, 350),
		Show Control Panel(0),
		Show Footer(0),
		Variables(X(x_col[1]), Y(y_cols[i]), Color( :Flag )),
		Elements(Points(X, Y, Legend(24))),
		invisible,
		SendToReport(
		Dispatch(
			{},
			"Graph Builder",
			OutlineBox,
			{Set Title( y_name || " vs " || x_name ), Image Export Display( Normal )}
			),
		Dispatch(
			{},
			"Graph Builder",
			FrameBox,
			{Marker Size( 5 ), Transparency(1)}
			),
		Dispatch( 
			{},
			"graph title", 
			TextEditBox, 
			{Set Text( "" )} 
			),
		Dispatch( 
			{}, 
			"X title", 
			TextEditBox, 
			{Set Text( "" )} 
			)
		)
	);
	gb << Show Legend(1);
	myVLB << append( Report( gb ) );
	gb << delete;
);
1 ACCEPTED SOLUTION

Accepted Solutions
jthi
Super User

Re: Auto exclude a certain item from the legend

You want to just hide the marker? Couldn't that cause confusion to the reader as there are markers in the plot but not explanation to them at all? 

 

I'm not sure if there are any very easy ways of doing this besides doing it interactively and then copying the script. Based on JMP created script this looks to be legend item position dependent thing (seems like index starts from 0 here... and index 1 is set to -1 to hide it).

Graph Builder(
	Variables(X(:height), Y(:weight), Color(:sex)),
	Elements(Points(X, Y, Legend(18))),
	SendToReport(Dispatch({}, "400", LegendBox, {Legend Position({18, [0, -1]})}))
)

Here is maybe a bit more robust option using Legend Display (see LegendBox object from scripting index)

Names Default To Here(1);
dt = Open("$SAMPLE_DATA/Big Class.jmp");
gb = dt << Graph Builder(
	Size(534, 456),
	Show Control Panel(0),
	Variables(X(:height), Y(:weight), Color(:sex)),
	Elements(Points(X, Y, Legend(1)))
);

lgnd = gb << Get Legend Display;
items = lgnd << Get Items;

For Each({item}, items, 
	show(item << get label);
	If(item << Get Label == "M", 
		item << Set Visible(0)
	)
);
-Jarmo

View solution in original post

2 REPLIES 2
jthi
Super User

Re: Auto exclude a certain item from the legend

You want to just hide the marker? Couldn't that cause confusion to the reader as there are markers in the plot but not explanation to them at all? 

 

I'm not sure if there are any very easy ways of doing this besides doing it interactively and then copying the script. Based on JMP created script this looks to be legend item position dependent thing (seems like index starts from 0 here... and index 1 is set to -1 to hide it).

Graph Builder(
	Variables(X(:height), Y(:weight), Color(:sex)),
	Elements(Points(X, Y, Legend(18))),
	SendToReport(Dispatch({}, "400", LegendBox, {Legend Position({18, [0, -1]})}))
)

Here is maybe a bit more robust option using Legend Display (see LegendBox object from scripting index)

Names Default To Here(1);
dt = Open("$SAMPLE_DATA/Big Class.jmp");
gb = dt << Graph Builder(
	Size(534, 456),
	Show Control Panel(0),
	Variables(X(:height), Y(:weight), Color(:sex)),
	Elements(Points(X, Y, Legend(1)))
);

lgnd = gb << Get Legend Display;
items = lgnd << Get Items;

For Each({item}, items, 
	show(item << get label);
	If(item << Get Label == "M", 
		item << Set Visible(0)
	)
);
-Jarmo
Kenobi
Level III

Re: Auto exclude a certain item from the legend

Thank you very much. This works. I had an additional query. Is it possible to export a custom legend from outside in this script?