cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
] />

Discussions

Solve problems, and share tips and tricks with other JMP users.
Choose Language Hide Translation Bar

Add vertical lines to Graph Builder in H List Box

Hi,

I want to put several graphs in a single plot and use the Graph Builder together with V List Box and H List Box. I want to add vertical lines to the plots. I found the example by @jthi, however I get problems as soon as there a several plots.

The example below works with a single plot, but when I uncomment the second plot, I get an additional axis between the plots (see below). How can I fix that?

 

 



Names Default To Here(1);
dt = Open("$SAMPLE_DATA/Big Class.jmp");

//gender_list = {"F", "M" };
gender_list = {"F"};

For( i = 1, i < N Items( gender_list ) + 1, i++,
	gender = gender_list[i];
	dt_gender = dt << Subset(
		Filtered Rows( :sex == gender ),
		Include All Columns//Name :sex 
		);
		
	Match ( gender,
		"F", data = Column ("height"),
		"M", data = Column ("weight")
	);
	
	Match ( gender,
		"F", ref_line = 60,
		"M", ref_line = 100
	);

	plot = New Window ( gender,
		H List Box(
			gb1 = dt_gender << Graph Builder(
				Size(529, 457),
				Show Control Panel(0),
				Variables(X(data)),
				Elements(Histogram(X, Legend(3)))
			),	
			axisbox = Report(gb1)[AxisBox(1)],
			axisbox << Add Ref Line(ref_line, "Dotted", red, gender, 2),
			/*gb2 = dt_gender << Graph Builder(
				Size(529, 457),
				Show Control Panel(0),
				Variables(X(data)),
				Elements(Histogram(X, Legend(3)))
			),	*/
			//axisbox = Report(gb2)[AxisBox(1)],
			//axisbox << Add Ref Line(ref_line, "Dotted", red, gender, 2),
		),
	);
);

{D9BBC98D-7E75-463D-A174-4831C1E99F5E&#125;.png 

2 ACCEPTED SOLUTIONS

Accepted Solutions
hogi
Level XIII

Re: Add vertical lines to Graph Builder in H List Box

In New Window, different display objects can be listed by separating them with commas:

gb = graph Box ();
new window("test",
Text Box ("Hello"),
gb [Axis Box (2)]
)

creates a new window with the text box and an Axis box.

If you want to add "commands to this list, you have to "close" the commands with ";".

For your case it's:

View more...

 

Names Default To Here(1);
dt = Open("$SAMPLE_DATA/Big Class.jmp");

//gender_list = {"F", "M" };
gender_list = {"F"};

For( i = 1, i < N Items( gender_list ) + 1, i++,
	gender = gender_list[i];
	dt_gender = dt << Subset(
		Filtered Rows( :sex == gender ),
		Include All Columns//Name :sex 
		);
		
	Match ( gender,
		"F", data = Column ("height"),
		"M", data = Column ("weight")
	);
	
	Match ( gender,
		"F", ref_line = 60,
		"M", ref_line = 100
	);

	plot = New Window ( gender,
		H List Box(
			gb1 = dt_gender << Graph Builder(
				Size(529, 457),
				Show Control Panel(0),
				Variables(X(data)),
				Elements(Histogram(X, Legend(3)))
			),	
			axisbox = Report(gb1)[AxisBox(1)];
			axisbox << Add Ref Line(ref_line, "Dotted", red, gender, 2);
			gb2 = dt_gender << Graph Builder(
				Size(529, 457),
				Show Control Panel(0),
				Variables(X(data)),
				Elements(Histogram(X, Legend(3)))
			),	
			axisbox = Report(gb2)[AxisBox(1)];
			axisbox << Add Ref Line(ref_line, "Dotted", red, gender, 2);
		),
	);
);

View solution in original post

jthi
Super User

Re: Add vertical lines to Graph Builder in H List Box

I would suggest moving the code adding reference lines outside of New Window as it is easier (in my opinion) to update and make modifications to (you can also do what hogi suggested).

Here is initial idea how I would write this (not all of these are basic techniques, but this can give some ideas what can be done)

 

Names Default To Here(1);

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

plot_width = 400;
plot_height = 300;

aa_genders = Associative Array();
aa_genders["F"] = ["data" => "height", "ref_line" => 60];
aa_genders["M"] = ["data" => "weight", "ref_line" => 100];


For Each({{cur_gender, specs}}, aa_genders,
	dt_gender = dt << Subset(
		Filtered Rows(:sex == cur_gender),
		Include All Columns,
		Invisible
	);
	
	hlb = H List Box(
		gb1 = dt_gender << Graph Builder(
			Size(plot_width, plot_height),
			Show Control Panel(0),
			Variables(X(Eval(specs["data"]))),
			Elements(Histogram(X, Legend(3)))
		),
		gb2 = dt_gender << Graph Builder(
			Size(plot_width, plot_height),
			Show Control Panel(0),
			Variables(X(Eval(specs["data"]))),
			Elements(Histogram(X, Legend(3)))
		)
	);
	
	axisbox = Report(gb1)[AxisBox(1)];
	axisbox << Add Ref Line(specs["ref_line"], "Dotted", red, cur_gender, 2);
	
	axisbox = Report(gb2)[AxisBox(1)];
	axisbox << Add Ref Line(specs["ref_line"], "Dotted", red, cur_gender, 2);

	aa_genders[cur_gender]["dt"] = dt_gender;
	aa_genders[cur_gender]["report"] = New Window(cur_gender,
		hlb
	);
);

 

 

-Jarmo

View solution in original post

3 REPLIES 3
hogi
Level XIII

Re: Add vertical lines to Graph Builder in H List Box

In New Window, different display objects can be listed by separating them with commas:

gb = graph Box ();
new window("test",
Text Box ("Hello"),
gb [Axis Box (2)]
)

creates a new window with the text box and an Axis box.

If you want to add "commands to this list, you have to "close" the commands with ";".

For your case it's:

View more...

 

Names Default To Here(1);
dt = Open("$SAMPLE_DATA/Big Class.jmp");

//gender_list = {"F", "M" };
gender_list = {"F"};

For( i = 1, i < N Items( gender_list ) + 1, i++,
	gender = gender_list[i];
	dt_gender = dt << Subset(
		Filtered Rows( :sex == gender ),
		Include All Columns//Name :sex 
		);
		
	Match ( gender,
		"F", data = Column ("height"),
		"M", data = Column ("weight")
	);
	
	Match ( gender,
		"F", ref_line = 60,
		"M", ref_line = 100
	);

	plot = New Window ( gender,
		H List Box(
			gb1 = dt_gender << Graph Builder(
				Size(529, 457),
				Show Control Panel(0),
				Variables(X(data)),
				Elements(Histogram(X, Legend(3)))
			),	
			axisbox = Report(gb1)[AxisBox(1)];
			axisbox << Add Ref Line(ref_line, "Dotted", red, gender, 2);
			gb2 = dt_gender << Graph Builder(
				Size(529, 457),
				Show Control Panel(0),
				Variables(X(data)),
				Elements(Histogram(X, Legend(3)))
			),	
			axisbox = Report(gb2)[AxisBox(1)];
			axisbox << Add Ref Line(ref_line, "Dotted", red, gender, 2);
		),
	);
);

hogi
Level XIII

Re: Add vertical lines to Graph Builder in H List Box

I tried to add a screenshot, but Copy/Paste still seems to be broken on the Community
@Ryan_Gilmore ?

jthi
Super User

Re: Add vertical lines to Graph Builder in H List Box

I would suggest moving the code adding reference lines outside of New Window as it is easier (in my opinion) to update and make modifications to (you can also do what hogi suggested).

Here is initial idea how I would write this (not all of these are basic techniques, but this can give some ideas what can be done)

 

Names Default To Here(1);

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

plot_width = 400;
plot_height = 300;

aa_genders = Associative Array();
aa_genders["F"] = ["data" => "height", "ref_line" => 60];
aa_genders["M"] = ["data" => "weight", "ref_line" => 100];


For Each({{cur_gender, specs}}, aa_genders,
	dt_gender = dt << Subset(
		Filtered Rows(:sex == cur_gender),
		Include All Columns,
		Invisible
	);
	
	hlb = H List Box(
		gb1 = dt_gender << Graph Builder(
			Size(plot_width, plot_height),
			Show Control Panel(0),
			Variables(X(Eval(specs["data"]))),
			Elements(Histogram(X, Legend(3)))
		),
		gb2 = dt_gender << Graph Builder(
			Size(plot_width, plot_height),
			Show Control Panel(0),
			Variables(X(Eval(specs["data"]))),
			Elements(Histogram(X, Legend(3)))
		)
	);
	
	axisbox = Report(gb1)[AxisBox(1)];
	axisbox << Add Ref Line(specs["ref_line"], "Dotted", red, cur_gender, 2);
	
	axisbox = Report(gb2)[AxisBox(1)];
	axisbox << Add Ref Line(specs["ref_line"], "Dotted", red, cur_gender, 2);

	aa_genders[cur_gender]["dt"] = dt_gender;
	aa_genders[cur_gender]["report"] = New Window(cur_gender,
		hlb
	);
);

 

 

-Jarmo

Recommended Articles